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

gcc 12/13: -Warray-bounds when dereferencing value returned from TABLE_SHARE::db_type()

    XMLWordPrintable

Details

    Description

      See
      <https://buildbot.mariadb.net/buildbot/builders/kvm-deb-bookworm-amd64/builds/1122/steps/compile/logs/warnings%20%28214%29>:

      /home/buildbot/buildbot/build/mariadb-11.4.5/sql/sql_base.cc: In function ‘my_bool mysql_rm_tmp_tables()’:
      /home/buildbot/buildbot/build/mariadb-11.4.5/sql/sql_base.cc:9435:30: warning: array subscript 0 is outside array bounds of ‘handlerton [0]’ [-Warray-bounds]
       9435 |             share.db_type()->drop_table(share.db_type(), path_copy);
            |             ~~~~~~~~~~~~~~~~~^~~~~~~~~~
      ...
      /home/buildbot/buildbot/build/mariadb-11.4.5/sql/sql_partition.cc: In function ‘bool handle_list_of_fields(THD*, List_iterator<const char>, TABLE*, partition_info*, bool)’:
      /home/buildbot/buildbot/build/mariadb-11.4.5/sql/sql_partition.cc:720:32: warning: array subscript 0 is outside array bounds of ‘handlerton [0]’ [-Warray-bounds]
        720 |       if (table->s->db_type()->partition_flags &&
            |           ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
      In file included from /home/buildbot/buildbot/build/mariadb-11.4.5/sql/mariadb.h:29,
                       from /home/buildbot/buildbot/build/mariadb-11.4.5/sql/sql_partition.cc:50:
      /home/buildbot/buildbot/build/mariadb-11.4.5/sql/sql_partition.cc: In function ‘bool fix_partition_func(THD*, TABLE*, bool)’:
      /home/buildbot/buildbot/build/mariadb-11.4.5/sql/sql_partition.cc:2056:40: warning: array subscript 0 is outside array bounds of ‘handlerton [0]’ [-Warray-bounds]
       2056 |   if (unlikely((!(table->s->db_type()->partition_flags &&
            |                   ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
      /home/buildbot/buildbot/build/mariadb-11.4.5/include/my_global.h:365:44: note: in definition of macro ‘unlikely’
        365 | #define unlikely(x)     __builtin_expect(((x) != 0),0)
            |                                            ^
      /home/buildbot/buildbot/build/mariadb-11.4.5/sql/sql_partition.cc: In function ‘bool partition_key_modified(TABLE*, const MY_BITMAP*)’:
      /home/buildbot/buildbot/build/mariadb-11.4.5/sql/sql_partition.cc:2786:28: warning: array subscript 0 is outside array bounds of ‘handlerton [0]’ [-Warray-bounds]
       2786 |   if (table->s->db_type()->partition_flags &&
            |       ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
      

      Locally it requires at least -O3 in CMAKE_CXX_FLAGS to reproduce.
      Triggered even if we replace plugin_hton(db_plugin) with
      (handlerton *)((*db_plugin)->data) in db_type(). Therefore it
      looks like a false positive (or
      https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104828) to me.

      I was wondering whether -O3 causes Warray-bounds=2, but the warning
      also appears with -O3 -Warray-bounds=1.

      gcc versions:
      Mine:

      $ g++ --version
      g++ (Debian 13.2.0-13) 13.2.0

      In the buildbot stdout:

      g++ (Debian 12.2.0-14) 12.2.0

      Attachments

        Activity

          People

            ycp Yuchen Pei
            ycp Yuchen Pei
            Votes:
            0 Vote for this issue
            Watchers:
            4 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.