Comment 23 for bug 1905159

Revision history for this message
Jerzy Tarasiuk (tarasiukj) wrote :

'.B' directive writing 2 bytes into a region (mbbioDirectTest.c:44)

modules/database/test/std/rec/mbbioDirectTest.c
- line 38: use a larger 'field', e.g. char field[44]; ?
  but: the 'rec' arg can be up to "do-NNNNNNNNNN" (13-char)
  only and the sprintf in void testmbbioFields() can produce
  at most 4 more chars +terminator - 17 total; this is a G++
  bug - it sees the 'rec' declared size and assumes the whole
  size is to be used; need 'field' size to be 4 char bigger,
  but the 'rec' size can be 16-char, and the 'field' 20-char.
  (this assumes 'int' is 32-bit; for 64=bit int need 24/28)

The code which causes the warning is:

static
void testmbbioFields(const char* rec, unsigned int value)
{
    char field[40];
    unsigned int i;

    testdbGetFieldEqual(rec, DBF_ULONG, value);
    for (i=0; i < 32; i++)
    {
        sprintf(field,"%s.B%X", rec, i);
        testdbGetFieldEqual(field, DBF_ULONG, (value>>i)&1);
    }
}

static
void testmbbioRecords(unsigned int count, unsigned int value)
{
    char rec[40];
    unsigned int i;

    for (i = 1; i <= count; i++)
    {
        sprintf(rec, "do%d", i);
        testDiag(" ### %s ###", rec);
        testmbbioFields(rec, value);
        sprintf(rec, "di%d", i);
        testmbbioFields(rec, value);
    }
}