linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: Pointer Woes: Pointer to a Pointer
@ 2003-11-18 23:07 Joseph D. Wagner
  0 siblings, 0 replies; 4+ messages in thread
From: Joseph D. Wagner @ 2003-11-18 23:07 UTC (permalink / raw)
  To: glynn.clements; +Cc: linux-c-programming

> Given that you are using 1-based indexing, are you remembering to add 1
> to the number of elements when you (re)allocate the arrays
> (frag_log.block_order_log, block_order_log.block_id and all of the
> individual block_id arrays)?

In answering your question, this is where the code gets a little messy.  I'm 
99.999% sure that what you said IS the case for all of the 'frag_log' 
elements (after all, THAT code works, i.e. the rest of the program works 
fine if I take this one problematic line of code out), but I'm not so sure 
about all of the individual block_order_log.block_id elements.

Thanks again for all of your help.

Joseph D. Wagner

struct block_order_log_t
{
    e2_blkcnt_t total_blocks;
    size_t is_indirect_block_array_size;
    bool *is_indirect_block;
    size_t block_id_array_size;
    blk_t *block_id;
};

struct fragments_log_t
{
    u_int32_t total_fragmented_files;
    size_t inode_id_array_size;
    ext2_ino_t *inode_id;
    size_t parent_inode_id_array_size;
    ext2_ino_t *parent_inode_id;
    size_t total_fragments_array_size;
    e2_blkcnt_t *total_fragments;
    size_t block_order_log_array_size;
    struct block_order_log_t *block_order_log;
};

...

if(total_fragments > 0)
{
    frag_log.total_fragmented_files++;

    /* Allocates more memory for the fragments log */
    frag_log.inode_id_array_size =
        (frag_log.total_fragmented_files + 1) *
        sizeof(ext2_ino_t);
    frag_log.inode_id = (ext2_ino_t*) realloc(
        frag_log.inode_id,
        frag_log.inode_id_array_size);
    if(frag_log.inode_id == NULL)
    {
        ...
    }
    frag_log.parent_inode_id_array_size =
        (frag_log.total_fragmented_files + 1) *
        sizeof(ext2_ino_t);
    frag_log.parent_inode_id = (ext2_ino_t*) realloc(
        frag_log.parent_inode_id,
        frag_log.parent_inode_id_array_size);
    if(frag_log.parent_inode_id == NULL)
    {
        ...
    }
    frag_log.total_fragments_array_size =
        (frag_log.total_fragmented_files + 1) *
        sizeof(e2_blkcnt_t);
    frag_log.total_fragments = (e2_blkcnt_t*) realloc(
        frag_log.total_fragments,
        frag_log.total_fragments_array_size);
    if(frag_log.total_fragments == NULL)
    {
        ...
    }
    frag_log.block_order_log_array_size =
        (frag_log.total_fragmented_files + 1) *
        sizeof(struct block_order_log_t);
    frag_log.block_order_log = (struct block_order_log_t*)
        realloc(frag_log.block_order_log,
        frag_log.block_order_log_array_size);
    if(frag_log.block_order_log == NULL)
    {
        ...
    }
    frag_log.block_order_log->is_indirect_block_array_size +=
        block_order_log.total_blocks * sizeof(bool);
    frag_log.block_order_log->is_indirect_block = (bool*)
        realloc(frag_log.block_order_log->is_indirect_block,
        frag_log.block_order_log->is_indirect_block_array_size);
    if(frag_log.block_order_log->is_indirect_block == NULL)
    {
        ...
    }
    frag_log.block_order_log->block_id_array_size +=
        block_order_log.total_blocks * sizeof(blk_t);
    frag_log.block_order_log->block_id = (blk_t*) realloc(
        frag_log.block_order_log->block_id,
        frag_log.block_order_log->block_id_array_size);
    if(frag_log.block_order_log->block_id == NULL)
    {
        ...
    }

...


^ permalink raw reply	[flat|nested] 4+ messages in thread
* Re: Pointer Woes: Pointer to a Pointer
@ 2003-11-19 15:29 Joseph D. Wagner
  0 siblings, 0 replies; 4+ messages in thread
From: Joseph D. Wagner @ 2003-11-19 15:29 UTC (permalink / raw)
  To: linux-c-programming

RESOLVED

Element zero in the array was not being free'd.

Joseph D. Wagner


^ permalink raw reply	[flat|nested] 4+ messages in thread
* Pointer Woes: Pointer to a Pointer
@ 2003-11-18  8:30 Joseph D. Wagner
  2003-11-18 21:42 ` Glynn Clements
  0 siblings, 1 reply; 4+ messages in thread
From: Joseph D. Wagner @ 2003-11-18  8:30 UTC (permalink / raw)
  To: linux-c-programming

valgrind (a.k.a. memcheck) says that the single line inside the 'for' loop 
below is the cause of my problems, saying things like 'uninitialized 
memory' and 'invalid write'.  However, I can't figure out where I went 
wrong in the line within my for loop.  I'd appreciate an extra/fresh set of 
eyes.

Is the problem in the single line inside the 'for' loop below, or is the 
problem somewhere back in my realloc statements?

FYI:
e2_blkcnt_t is signed 64-bit int
ext2_int_t is unsigned 32-bit int
frag_log is a global variable
block_order_log is a local variable reused for each file examined

TIA.

Joseph D. Wagner

struct block_order_log_t
{
    e2_blkcnt_t total_blocks;
    size_t is_indirect_block_array_size;
    bool *is_indirect_block;
    size_t block_id_array_size;
    blk_t *block_id;
};

struct fragments_log_t
{
    u_int32_t total_fragmented_files;
    size_t inode_id_array_size;
    ext2_ino_t *inode_id;
    size_t parent_inode_id_array_size;
    ext2_ino_t *parent_inode_id;
    size_t total_fragments_array_size;
    e2_blkcnt_t *total_fragments;
    size_t block_order_log_array_size;
    struct block_order_log_t *block_order_log;
};

...

for(e2_blkcnt_t index = 1;
    index <= block_order_log.total_blocks;
    index++)
{
    *((frag_log.block_order_log + frag_log.total_fragmented_files)->block_id 
+ index) = *(block_order_log.block_id + index);
}


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-11-19 15:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-11-18 23:07 Pointer Woes: Pointer to a Pointer Joseph D. Wagner
  -- strict thread matches above, loose matches on Subject: below --
2003-11-19 15:29 Joseph D. Wagner
2003-11-18  8:30 Joseph D. Wagner
2003-11-18 21:42 ` Glynn Clements

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).