Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-30401

Bitmap type - Shifting 64-bit value by 64 bits is undefined (cppcheck)

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Not a Bug
    • 10.5.18
    • N/A
    • Server
    • None

    Description

      This is a cppcheck found item. Seems to be valid. Not 100% sure.

      10.11

      Checking storage/perfschema/pfs_global.cc: O_NONBLOCK=1;INT_MAX=0x7FFFFFFF;MAP_ANONYMOUS=1;__GNUC__=1;HAVE_CONFIG_H=1;MYSQL_SERVER=1;_FILE_OFFSET_BITS=64;NDEBUG=1;_FORTIFY_SOURCE=2;DBUG_OFF=1;HAVE_OPENSSL=1;OPENSSL_API_COMPAT=0x10100000L...
      mariadb-server-10.11/sql/sql_bitmap.h:78:39: error: Shifting 64-bit value by 64 bits is undefined behaviour [shiftTooManyBits]
          return ARRAY_ELEMENTS == 1 ? 1ULL << n : 1ULL << (n % BITS_PER_ELEMENT);
                                            ^
      sql/sql_bitmap.h:190:53: note: Calling function 'last_element_mask', 1st argument '64' value is 64
            buffer[ARRAY_ELEMENTS - 1]= last_element_mask(width);
                                                          ^
      mariadb-server-10.11/sql/sql_bitmap.h:83:21: note: Calling function 'bit_mask', 1st argument 'n' value is 64
          return bit_mask(n) - 1;
                          ^
      mariadb-server-10.11/sql/sql_bitmap.h:78:39: note: Shift
          return ARRAY_ELEMENTS == 1 ? 1ULL << n : 1ULL << (n % BITS_PER_ELEMENT);
                                            ^
      

      What this doesn't show is sql_bitmask.h:77

      DBUG_ASSERT(n < width);
      

      So last_element_mask(width) - results in bit_mask(width) which misses the DBUG_ASSERT(n < width) in production builds.

      This would get called in:

      storage/maria/ha_maria.cc:ha_maria::info    share->keys_in_use.intersect_extended(maria_info.key_map);
      

      (and myisam in same way).

      Attachments

        Issue Links

          Activity

            People

              wlad Vladislav Vaintroub
              danblack Daniel Black
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.