Ignore:
Timestamp:
2012-03-07T17:32:33+13:00 (10 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/indexers/mgpp/lib/unitool.cpp

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