Uploaded image for project: 'WiredTiger'
  1. WiredTiger
  2. WT-12715

Fix WT_STRING_MATCH for empty strings and optimize

    • Storage Engines

      The beleaguered WT_STRING_MATCH macro has an error when the second string is zero length.

      #include <stdio.h>
      #include <string.h>
      #include <stdbool.h>
      
      #define WT_STRING_MATCH(str, bytes, len) __wt_string_match(str, bytes, len)
      static inline bool
      __wt_string_match(const char *str, const char *bytes, size_t len)
      {
        return (len == 0 || (strncmp(str, bytes, len) == 0 && str[len] == '\0'));
      }
      
      
      void main(void) {
        const char *nothing = "";
      
        printf("returns %d\n", WT_STRING_MATCH("something", nothing, 0));
      }
      

      This prints 1, that is, true.  In the way this macro is used, this should behave differently from memcmp, not the same.

            Assignee:
            donald.anderson@mongodb.com Donald Anderson
            Reporter:
            donald.anderson@mongodb.com Donald Anderson
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: