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

fix uintNkorr in byte_order_generic.h, avoid unaligned access

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 10.6, 10.11, 11.4, 12.1
    • None
    • Compiling, Server
    • None

    Description

      Compilers are getting (too) smart, and they can generate incorrect code, for unaligned access, since it is "undefined behavior".

      Also, avoid macros, like MySQL did, it is almost impossible to read now. `static inline` is good enough, and documents correct datatype
      of the return value.

      • the correct optimization for all little endian is something like this.

      static inline uint uint4korr(const void *p)
      {
        uint ret;
        memcpy(&ret, p, 4);
        return ret;
      }
      

      It is optimized by the compiler to a single instruction, if alignment is unimportant in that architecture.
      Corollary : There is no whatever reason to have special code for Intel, memcpy is the best.
      We only need set of such static inline functions for big and little endian architectures, nothing more.

      For big-endian, byte-wise reading and calculating are in order. That code might also by optimized by the compiler, if architecture has a byteswapping instructions.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              wlad Vladislav Vaintroub
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

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