Ignore:
Timestamp:
2011-06-15T14:46:59+12:00 (13 years ago)
Author:
mdewsnip
Message:

Fixed problem in Greenstone's unitool::create_unicat_data() causing crashes on 64-bit machines (when Greenstone is compiled in 64-bit mode). The old malloc() parameter calculation assumed that an unsigned long was always 4 bytes, but this isn't true on 64-bit machines. Although the space required for this structure is actually the same on 64-bit machines (2 bits are needed for each of 65536 values), the rest of the code assumes the machine is 32-bit and there are 16 values per array entry. Rather than trying to change the rest of the code to work on both 32-bit and 64-bit machines, I've just changed this calculation so the block allocated is twice the size on 64-bit machines. This is a bit wasteful because half the space isn't used, but it's only 16KB so I don't think it's worth worrying about.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/common-src/src/lib/unitool.cpp

    r23423 r24162  
    14831483
    14841484  if (unicode_cat_data != NULL) return;
    1485   unicode_cat_data = (unsigned long *) malloc (0x10000/4);
     1485  // 64-BIT FIX: The old malloc() parameter calculation assumed that an unsigned long was always 4 bytes, but this
     1486  //   isn't true on 64-bit machines. Although the space required for this structure is actually the same on 64-bit
     1487  //   machines (2 bits are needed for each of 65536 values), the rest of the code assumes the machine is 32-bit
     1488  //   and there are 16 values per array entry. Rather than trying to change the rest of the code to work on both
     1489  //   32-bit and 64-bit machines, I've just changed this calculation so the block allocated is twice the size on
     1490  //   64-bit machines. This is a bit wasteful because half the space isn't used, but it's only 16KB so I don't
     1491  //   think it's worth worrying about. [Michael Dewsnip, DL Consulting Ltd.]
     1492  unicode_cat_data = (unsigned long *) malloc((0x10000 / 16) * sizeof(unsigned long));
    14861493  if (unicode_cat_data == NULL) return;
    14871494 
Note: See TracChangeset for help on using the changeset viewer.