Bug #61180 *korr/*store macros in my_global.h assume the argument to be a char pointer
Submitted: 15 May 2011 15:53 Modified: 25 Feb 2014 16:17
Reporter: Alexey Kopytov Email Updates:
Status: Closed Impact on me:
Category:MySQL Server: General Severity:S3 (Non-critical)
Version:5.1, 5.5 OS:Any
Assigned to: CPU Architecture:Any
Triage: Needs Triage: D3 (Medium)

[15 May 2011 15:53] Alexey Kopytov
Many *korr/*store macros in my_global.h assume the argument to be a char pointer, for example:

#define uint3korr(A)	(uint32) (((uint32) ((uchar) (A)[0])) +\
				  (((uint32) ((uchar) (A)[1])) << 8) +\
				  (((uint32) ((uchar) (A)[2])) << 16))

That will not work correctly if A is not a pointer to a 1-byte type. For example, there is the following code in Bitmap<default_width>::to_ulonglong():

  ulonglong to_ulonglong() const
    if (sizeof(buffer) >= 8)
      return uint8korr(buffer);
    DBUG_ASSERT(sizeof(buffer) >= 4);
    return (ulonglong) uint4korr(buffer);

where buffer is declared as "uint32 buffer[(default_width+31)/32];".

So either the code should be revised to make sure the arguments to those macros are always cast to "uchar *", or the cast should be done in the macros.

How to repeat:
See the bug description.
[17 May 2011 18:23] Sinisa Milivojevic
Kaamos, my dear friend,

I checked a code and seems like a first class is used for cases which are up to 32 bits wide, while the second one is used for other cases. Although, it is not documented.

Please, tell me if you think that I am wrong.
[17 May 2011 19:10] Alexey Kopytov

I assume you are referring to the Bitmap<> class templates. Bitmap<uint default_width> is a general implementation for arbitrarily-sized bitmaps, and Bitmap<64> is an optimized version which stores and processes bitmaps as a 64-bit integer.
[18 May 2011 14:34] Sinisa Milivojevic

I agree with you, but do you have an example in our code where default_width is larger then 32 bits.
[18 May 2011 14:43] Alexey Kopytov

It is larger than 64 if you build with --with-max-indexes=128. Don't know if there are other users of that template.
[18 May 2011 14:51] Alexey Kopytov
It's one of the reasons for bug #54127.
[18 May 2011 17:15] Sinisa Milivojevic

Well, this time I agree with you ...... ;o)

Although it is hard for me to admit such things ....
[25 Feb 2014 16:17] Paul Dubois
Fixed in 5.7.4. No user impact; no changelog entry required.