[Asterisk-code-review] Fix sscanf() format string type mismatch. (asterisk[13])

Joshua Colp asteriskteam at digium.com
Mon Dec 14 16:37:51 CST 2015


Joshua Colp has submitted this change and it was merged.

Change subject: Fix sscanf() format string type mismatch.
......................................................................


Fix sscanf() format string type mismatch.

ASTERISK-25615
Reported by: George Joseph

Change-Id: Ieff35307254ca193f3d473cff2e396ca57c7ce0b
---
M include/asterisk/utils.h
M main/utils.c
2 files changed, 23 insertions(+), 19 deletions(-)

Approvals:
  Anonymous Coward #1000019: Verified
  Joshua Colp: Looks good to me, approved
  George Joseph: Looks good to me, but someone else must approve



diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h
index cfb78c0..c7a4737 100644
--- a/include/asterisk/utils.h
+++ b/include/asterisk/utils.h
@@ -1105,9 +1105,10 @@
  *
  * \param version1.
  * \param version2.
- * \return -1 if version 1 < version 2.
- * \return 0 if version 1 = version 2.
- * \return 1 if version 1 > version 2.
+ *
+ * \return <0 if version 1 < version 2.
+ * \return =0 if version 1 = version 2.
+ * \return >0 if version 1 > version 2.
  */
 int ast_compare_versions(const char *version1, const char *version2);
 
diff --git a/main/utils.c b/main/utils.c
index f06b16c..3a8d46a 100644
--- a/main/utils.c
+++ b/main/utils.c
@@ -2958,23 +2958,26 @@
 
 int ast_compare_versions(const char *version1, const char *version2)
 {
-	u_int64_t major[2] = { 0 };
-	u_int64_t minor[2] = { 0 };
-	u_int64_t patch[2] = { 0 };
-	u_int64_t extra[2] = { 0 };
-	u_int64_t v1, v2;
+	unsigned int major[2] = { 0 };
+	unsigned int minor[2] = { 0 };
+	unsigned int patch[2] = { 0 };
+	unsigned int extra[2] = { 0 };
+	int res;
 
-	sscanf(version1, "%lu.%lu.%lu.%lu", &major[0], &minor[0], &patch[0], &extra[0]);
-	sscanf(version2, "%lu.%lu.%lu.%lu", &major[1], &minor[1], &patch[1], &extra[1]);
+	sscanf(version1, "%u.%u.%u.%u", &major[0], &minor[0], &patch[0], &extra[0]);
+	sscanf(version2, "%u.%u.%u.%u", &major[1], &minor[1], &patch[1], &extra[1]);
 
-	v1 = major[0] << 48 | minor[0] << 32 | patch[0] << 16 | extra[0];
-	v2 = major[1] << 48 | minor[1] << 32 | patch[1] << 16 | extra[1];
-
-	if (v1 < v2) {
-		return -1;
-	} else if (v1 > v2) {
-		return 1;
-	} else {
-		return 0;
+	res = major[0] - major[1];
+	if (res) {
+		return res;
 	}
+	res = minor[0] - minor[1];
+	if (res) {
+		return res;
+	}
+	res = patch[0] - patch[1];
+	if (res) {
+		return res;
+	}
+	return extra[0] - extra[1];
 }

-- 
To view, visit https://gerrit.asterisk.org/1814
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ieff35307254ca193f3d473cff2e396ca57c7ce0b
Gerrit-PatchSet: 3
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: George Joseph <george.joseph at fairview5.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>



More information about the asterisk-code-review mailing list