Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-2618

ASSERT_CMP macros should copy argument values

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.11.0
    • Affects Version/s: None
    • Component/s: None

      The ASSERT_CMP macros like ASSERT_CMPINT use the arguments that are being compared directly in the error message.

      For example, the ASSERT_CMPINT approximately looks like:

      #define ASSERT_CMPINT(a, b)                  \
      if (a != b) {                                \
         printf("assert failure: %d != %d", a, b); \
         abort();                                  \ 
      } 
      

      The caveat is that if a or b are function calls (that aren't idempotent), the error message might be misleading.

      Here's an example of one such case:

      ASSERT_CMPINT (
          0, ==, bson_json_reader_read (reader, &bson_out, &error));
      

      Since b is substituted for that function call, that function gets called twice, and the error message could produce something confusing like "0 != 0".

            Assignee:
            spencer.mckenney Spencer Mckenney
            Reporter:
            kevin.albertson@mongodb.com Kevin Albertson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: