Ok, here's a bit of fun. I've been adding a few things to my mud, and I
ran across this odd...fluke.

(max_info is == 2 btw)
<gdb snip>
2550            for ( i = 0; i < max_info; i++ )
(gdb)
2552                    fprintf( fp, "#INFO\n" );
(gdb)
2553                    ttemp = (void*)&info_table[i];
(gdb)
2554                    save_struct( fp, &info, infosavetable, ttemp );

(gdb) print ttemp
$1 = (void *) 0xb085c80
(gdb) print &info_table[0]
$2 = (INFO *) 0xb085c80
(gdb) n
2555                    fprintf( fp, "#END\n\n" );
(gdb)
2556            }
(gdb)
2552                    fprintf( fp, "#INFO\n" );
(gdb)
2553                    ttemp = (void*)&info_table[i];
(gdb)
2554                    save_struct( fp, &info, infosavetable, ttemp );

(gdb) print ttemp
$3 = (void *) 0xb085c88
(gdb) print &info_table[1]
$4 = (INFO *) 0xb085c98

(gdb) s
save_struct (fp=0xa030c24, typebase=0x62fed4, table=0x592ec0,
    puntero=0xb085c88) at olc_tablesave.cc:1298
1298            int cnt = 0, i,j;
(gdb)
</gdb snip>

Now, the problem with this line of debugging is the info table. As you
can see, the first loop through went fine. The second, however,
displayed a discrepancy. ttemp is pointing to a different memory address
than it should be based on the assignment. It moves up 8 bytes in mem,
but the actual struct size is 18... (as shown by the print
&info_table[1] command). I put the ttemp in there for debugging
purposes, since prior, the discrepancy showed up as puntero in the
save_struct info.

To produce this problem, I have one entry in the table, with data, and I
realloc the table to max_info+1 as shown below. The interesting thing
is, if I don't fill out any of the structure's variables, I can continue
to realloc more without any problem. It is just when I realloc in this
once instance (as far as I've seen so far)

<snip>
                info = (INFO*) realloc( info_table, sizeof( INFO ) *
(max_info+1) );
                if ( info == NULL )
                {
                        bug( "failed to realloc info table", 0 );
                        return FALSE;
                }

                info_table = info;

                /* I initialize all the member variables here */

                max_info++;
                save_info();
                send_to_char( "New entry added to table.\n\r", ch );
                return FALSE;
</snip>

Now, the only thing I can think of that would be causing this is the
compiler doesn't recognize the correct struct size of INFO (the type of
info_table), so the [1] isn't computed properly... I've done a clean
compile, so that is not the problem.

Any ideas?

Ammaross Danan


Reply via email to