about summary refs log tree commit diff
path: root/support/support_test_compare_failure.c
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2018-01-08 13:01:36 +0100
committerFlorian Weimer <fweimer@redhat.com>2018-01-08 20:07:24 +0100
commit2b3aa44656dd873e2753c98fdcb95be6a9d147a6 (patch)
tree7c6df54631968d08cc407487b20b93c5123baac6 /support/support_test_compare_failure.c
parent630f4cc3aa019ede55976ea561f1a7af2f068639 (diff)
downloadglibc-2b3aa44656dd873e2753c98fdcb95be6a9d147a6.tar.gz
glibc-2b3aa44656dd873e2753c98fdcb95be6a9d147a6.tar.xz
glibc-2b3aa44656dd873e2753c98fdcb95be6a9d147a6.zip
support: Increase usability of TEST_COMPARE
The previous implementation of the TEST_COMPARE macro would fail
to compile code like this:

  int ret = res_send (query, sizeof (query), buf, sizeof (buf));
  TEST_COMPARE (ret,
                sizeof (query)
                + 2             /* Compression reference.  */
                + 2 + 2 + 4 + 2 /* Type, class, TTL, RDATA length.  */
                + 1             /* Pascal-style string length.  */
                + strlen (expected_name));

This resulted in a failed static assertion, "integer conversions
may alter sign of operands".  A user of the TEST_COMPARE would have
to add a cast to fix this.

This patch reverts to the original proposed solution of a run-time
check, making TEST_COMPARE usable for comparisons of numbers with
types with different signedness in more contexts.
Diffstat (limited to 'support/support_test_compare_failure.c')
-rw-r--r--support/support_test_compare_failure.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/support/support_test_compare_failure.c b/support/support_test_compare_failure.c
index a789283f86..e5596fd121 100644
--- a/support/support_test_compare_failure.c
+++ b/support/support_test_compare_failure.c
@@ -20,14 +20,14 @@
 #include <support/check.h>
 
 static void
-report (const char *which, const char *expr, long long value, int negative,
+report (const char *which, const char *expr, long long value, int positive,
         int size)
 {
   printf ("  %s: ", which);
-  if (negative)
-    printf ("%lld", value);
-  else
+  if (positive)
     printf ("%llu", (unsigned long long) value);
+  else
+    printf ("%lld", value);
   unsigned long long mask
     = (~0ULL) >> (8 * (sizeof (unsigned long long) - size));
   printf (" (0x%llx); from: %s\n", (unsigned long long) value & mask, expr);
@@ -37,11 +37,11 @@ void
 support_test_compare_failure (const char *file, int line,
                               const char *left_expr,
                               long long left_value,
-                              int left_negative,
+                              int left_positive,
                               int left_size,
                               const char *right_expr,
                               long long right_value,
-                              int right_negative,
+                              int right_positive,
                               int right_size)
 {
   support_record_failure ();
@@ -50,6 +50,6 @@ support_test_compare_failure (const char *file, int line,
             file, line, left_size * 8, right_size * 8);
   else
     printf ("%s:%d: numeric comparison failure\n", file, line);
-  report (" left", left_expr, left_value, left_negative, left_size);
-  report ("right", right_expr, right_value, right_negative, right_size);
+  report (" left", left_expr, left_value, left_positive, left_size);
+  report ("right", right_expr, right_value, right_positive, right_size);
 }