Bug #61178 Incorrect implementation of intersect(ulonglong) in non-optimized Bitmap class
Submitted: 15 May 2011 15:10 Modified: 15 May 2011 15:50
Reporter: Alexey Kopytov Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: General Severity:S3 (Non-critical)
Version:5.1, 5.5 OS:Any
Assigned to: CPU Architecture:Any
Triage: Needs Triage: D2 (Serious)

[15 May 2011 15:10] Alexey Kopytov
Description:
In "template <uint default_width> class Bitmap", intersect(ulonglong) is implemented as follows:

  void intersect(ulonglong map2buff)
  {
    MY_BITMAP map2;
    bitmap_init(&map2, (uint32 *)&map2buff, sizeof(ulonglong)*8, 0);
    bitmap_intersect(&map, &map2);
  }

This implementation does not take into account that bitmap_init() initializes the supplied buffer with zeroes. As a result, 0 is always returned due to intersecting with a zero bitmap.

How to repeat:
Examine the code in Bitmap<default_width>::intersect(ulonglong map2buff).
[15 May 2011 15:50] Valeriy Kravchuk
Indeed, bitmap_init() ends up with:

bitmap_clear_all(map);

and it is defined in my_bitmap.h as:

#define bitmap_clear_all(MAP) \
  { memset((MAP)->bitmap, 0, 4*no_words_in_map((MAP))); }
[25 Nov 2014 9:29] Laurynas Biveinis
This has been fixed in 5.7.1 in revno 5170.