summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Ates <joseph.ates@msasafety.com>2015-12-20 16:29:09 -0500
committerAndreas Schneider <asn@cryptomilk.org>2016-09-21 11:25:46 +0200
commitb516b621f78ed89b353240c1ea09ab76c5dbe6be (patch)
tree964916ccbc537ffc7c7a07f52be0e5a5de717dbb
parent4d7c402482cf2b205ea94b73c6b3206d8964272e (diff)
downloadcmocka-b516b621f78ed89b353240c1ea09ab76c5dbe6be.tar.gz
cmocka-b516b621f78ed89b353240c1ea09ab76c5dbe6be.tar.bz2
cmocka-b516b621f78ed89b353240c1ea09ab76c5dbe6be.zip
Fixed format specifier width mismatch
On some platforms PRIu64 is not necessarily the width of the LargestIntegralType. A new decimal format specifier for LargestIntegralType was added and replaces the invocations of PRIu64.
-rw-r--r--include/cmocka.h15
-rw-r--r--src/cmocka.c20
2 files changed, 28 insertions, 7 deletions
diff --git a/include/cmocka.h b/include/cmocka.h
index 282963d..4be40ea 100644
--- a/include/cmocka.h
+++ b/include/cmocka.h
@@ -79,7 +79,7 @@ typedef uintmax_t LargestIntegralType;
#endif /* LargestIntegralType */
#endif /* DOXYGEN */
-/* Printf format used to display LargestIntegralType. */
+/* Printf format used to display LargestIntegralType as a hexidecimal. */
#ifndef LargestIntegralTypePrintfFormat
# ifdef _WIN32
# define LargestIntegralTypePrintfFormat "0x%I64x"
@@ -92,6 +92,19 @@ typedef uintmax_t LargestIntegralType;
# endif /* _WIN32 */
#endif /* LargestIntegralTypePrintfFormat */
+/* Printf format used to display LargestIntegralType as a decimal. */
+#ifndef LargestIntegralTypePrintfFormatDecimal
+# ifdef _WIN32
+# define LargestIntegralTypePrintfFormatDecimal "%I64u"
+# else
+# if __WORDSIZE == 64
+# define LargestIntegralTypePrintfFormatDecimal "%lu"
+# else
+# define LargestIntegralTypePrintfFormatDecimal "%llu"
+# endif
+# endif /* _WIN32 */
+#endif /* LargestIntegralTypePrintfFormat */
+
/* Perform an unsigned cast to LargestIntegralType. */
#define cast_to_largest_integral_type(value) \
((LargestIntegralType)(value))
diff --git a/src/cmocka.c b/src/cmocka.c
index 829dd7a..abe1863 100644
--- a/src/cmocka.c
+++ b/src/cmocka.c
@@ -1055,10 +1055,11 @@ static int value_in_set_display_error(
if (succeeded) {
return 1;
}
- cm_print_error("%" PRIu64 " is %sin the set (", value,
- invert ? "" : "not ");
+ cm_print_error(LargestIntegralTypePrintfFormatDecimal
+ " is %sin the set (",
+ value, invert ? "" : "not ");
for (i = 0; i < size_of_set; i++) {
- cm_print_error("%" PRIu64 ", ", set[i]);
+ cm_print_error(LargestIntegralTypePrintfFormat ", ", set[i]);
}
cm_print_error(")\n");
}
@@ -1077,7 +1078,10 @@ static int integer_in_range_display_error(
if (value >= range_min && value <= range_max) {
return 1;
}
- cm_print_error("%" PRIu64 " is not within the range %" PRIu64 "-%" PRIu64 "\n",
+ cm_print_error(LargestIntegralTypePrintfFormatDecimal
+ " is not within the range "
+ LargestIntegralTypePrintfFormatDecimal "-"
+ LargestIntegralTypePrintfFormatDecimal "\n",
value, range_min, range_max);
return 0;
}
@@ -1094,7 +1098,10 @@ static int integer_not_in_range_display_error(
if (value < range_min || value > range_max) {
return 1;
}
- cm_print_error("%" PRIu64 " is within the range %" PRIu64 "-%" PRIu64 "\n",
+ cm_print_error(LargestIntegralTypePrintfFormatDecimal
+ " is within the range "
+ LargestIntegralTypePrintfFormatDecimal "-"
+ LargestIntegralTypePrintfFormatDecimal "\n",
value, range_min, range_max);
return 0;
}
@@ -1572,7 +1579,8 @@ void _assert_return_code(const LargestIntegralType result,
if (result > valmax - 1) {
if (error > 0) {
- cm_print_error("%s < 0, errno(%" PRIu64 "): %s\n",
+ cm_print_error("%s < 0, errno("
+ LargestIntegralTypePrintfFormatDecimal "): %s\n",
expression, error, strerror((int)error));
} else {
cm_print_error("%s < 0\n", expression);