~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/heap/ha_heap.cc

  • Committer: Jay Pipes
  • Date: 2009-09-18 17:15:07 UTC
  • mto: This revision was merged to the branch mainline in revision 1129.
  • Revision ID: jpipes@serialcoder-20090918171507-r4a6ahmln04ommww
Adds an error catch in heap_create_table which traps when a call to create a HEAP table with more than UINT32_MAX occurs.  This allows us to safely use a cast without worrying about truncation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
670
670
  TableShare *share= table_arg->s;
671
671
  bool found_real_auto_increment= 0;
672
672
 
 
673
  /* 
 
674
   * We cannot create tables with more rows than UINT32_MAX.  This is a
 
675
   * limitation of the HEAP engine.  Here, since TableShare::getMaxRows()
 
676
   * can return a number more than that, we trap it here instead of casting
 
677
   * to a truncated integer.
 
678
   */
 
679
  uint64_t num_rows= share->getMaxRows();
 
680
  if (num_rows > UINT32_MAX)
 
681
    return -1;
 
682
 
673
683
  if (!(columndef= (HP_COLUMNDEF*) malloc(column_count * sizeof(HP_COLUMNDEF))))
674
684
    return my_errno;
675
685
 
822
832
  hp_create_info.internal_table= internal_table;
823
833
  hp_create_info.max_chunk_size= share->block_size;
824
834
  hp_create_info.is_dynamic= (share->row_type == ROW_TYPE_DYNAMIC);
 
835
 
825
836
  error= heap_create(fn_format(buff,table_name,"","",
826
 
                               MY_REPLACE_EXT|MY_UNPACK_FILENAME),
827
 
                     keys, keydef,
828
 
                     column_count, columndef,
829
 
                     max_key_fieldnr, key_part_size,
830
 
                     share->reclength, mem_per_row_keys,
831
 
                     (uint32_t)share->getMaxRows(), 0, // Factor out MIN
832
 
                     &hp_create_info, internal_share);
 
837
                              MY_REPLACE_EXT|MY_UNPACK_FILENAME),
 
838
                    keys, keydef,
 
839
                    column_count, columndef,
 
840
                    max_key_fieldnr, key_part_size,
 
841
                    share->reclength, mem_per_row_keys,
 
842
                    static_cast<uint32_t>(num_rows), /* We check for overflow above, so cast is fine here. */
 
843
                    0, // Factor out MIN
 
844
                    &hp_create_info, internal_share);
833
845
 
834
846
  free((unsigned char*) keydef);
835
847
  free((void *) columndef);