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.
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 @@
#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 @@
# 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 @@
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 @@
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 @@
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 @@
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);