25
25
#pragma interface /* gcc class implementation */
26
26
#endif
27
27
28
- #define round_up_byte (size ) ((size + 7 ) >> 3 ) << 3
29
-
30
28
typedef enum ndb_item_type {
31
29
NDB_VALUE = 0 , // Qualified more with Item::Type
32
30
NDB_FIELD = 1 , // Qualified from table definition
@@ -333,22 +331,23 @@ class Ndb_cond_stack : public Sql_alloc
333
331
*/
334
332
class Ndb_expect_stack : public Sql_alloc
335
333
{
334
+ static const uint MAX_EXPECT_ITEMS = Item::VIEW_FIXER_ITEM + 1 ;
335
+ static const uint MAX_EXPECT_FIELD_TYPES = MYSQL_TYPE_GEOMETRY + 1 ;
336
+ static const uint MAX_EXPECT_FIELD_RESULTS = DECIMAL_RESULT + 1 ;
336
337
public:
337
338
Ndb_expect_stack (): collation(NULL ), length(0 ), max_length(0 ), next(NULL )
338
339
{
339
- // Allocate type checking bitmaps
340
- bitmap_init (&expect_mask,
341
- 0 , round_up_byte (Item::MAX_NUM_ITEMS), FALSE );
342
- bitmap_init (&expect_field_type_mask,
343
- 0 , round_up_byte (MYSQL_NUM_FIELD_TYPES), FALSE );
344
- bitmap_init (&expect_field_result_mask,
345
- 0 , round_up_byte (MYSQL_NUM_ITEM_RESULTS), FALSE );
340
+ // Allocate type checking bitmaps using fixed size buffers
341
+ // since max size is known at compile time
342
+ bitmap_init (&expect_mask, m_expect_buf,
343
+ MAX_EXPECT_ITEMS, FALSE );
344
+ bitmap_init (&expect_field_type_mask, m_expect_field_type_buf,
345
+ MAX_EXPECT_FIELD_TYPES, FALSE );
346
+ bitmap_init (&expect_field_result_mask, m_expect_field_result_buf,
347
+ MAX_EXPECT_FIELD_RESULTS, FALSE );
346
348
};
347
349
~Ndb_expect_stack ()
348
350
{
349
- bitmap_free (&expect_mask);
350
- bitmap_free (&expect_field_type_mask);
351
- bitmap_free (&expect_field_result_mask);
352
351
if (next)
353
352
delete next;
354
353
next= NULL ;
@@ -385,6 +384,11 @@ Ndb_expect_stack(): collation(NULL), length(0), max_length(0), next(NULL)
385
384
}
386
385
bool expecting (Item::Type type)
387
386
{
387
+ if (unlikely ((uint )type > MAX_EXPECT_ITEMS))
388
+ {
389
+ // Unknown type, can't be expected
390
+ return false ;
391
+ }
388
392
return bitmap_is_set (&expect_mask, (uint ) type);
389
393
}
390
394
void expect_nothing ()
@@ -411,6 +415,11 @@ Ndb_expect_stack(): collation(NULL), length(0), max_length(0), next(NULL)
411
415
}
412
416
bool expecting_field_type (enum_field_types type)
413
417
{
418
+ if (unlikely ((uint )type > MAX_EXPECT_FIELD_TYPES))
419
+ {
420
+ // Unknown type, can't be expected
421
+ return false ;
422
+ }
414
423
return bitmap_is_set (&expect_field_type_mask, (uint ) type);
415
424
}
416
425
void expect_no_field_type ()
@@ -433,6 +442,11 @@ Ndb_expect_stack(): collation(NULL), length(0), max_length(0), next(NULL)
433
442
}
434
443
bool expecting_field_result (Item_result result)
435
444
{
445
+ if (unlikely ((uint )result > MAX_EXPECT_FIELD_RESULTS))
446
+ {
447
+ // Unknown result, can't be expected
448
+ return false ;
449
+ }
436
450
return bitmap_is_set (&expect_field_result_mask,
437
451
(uint ) result);
438
452
}
@@ -484,6 +498,12 @@ Ndb_expect_stack(): collation(NULL), length(0), max_length(0), next(NULL)
484
498
}
485
499
486
500
private:
501
+ my_bitmap_map
502
+ m_expect_buf[bitmap_buffer_size(MAX_EXPECT_ITEMS)];
503
+ my_bitmap_map
504
+ m_expect_field_type_buf[bitmap_buffer_size(MAX_EXPECT_FIELD_TYPES)];
505
+ my_bitmap_map
506
+ m_expect_field_result_buf[bitmap_buffer_size(MAX_EXPECT_FIELD_RESULTS)];
487
507
MY_BITMAP expect_mask;
488
508
MY_BITMAP expect_field_type_mask;
489
509
MY_BITMAP expect_field_result_mask;
0 commit comments