From: "Joseph D. Wagner" <theman@josephdwagner.info>
To: glynn.clements@virgin.net
Cc: linux-c-programming@vger.kernel.org
Subject: Re: Pointer Woes: Pointer to a Pointer
Date: Wed, 19 Nov 2003 05:07:41 +0600 [thread overview]
Message-ID: <200311190507.41687.theman@josephdwagner.info> (raw)
> 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)
{
...
}
...
next reply other threads:[~2003-11-18 23:07 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-11-18 23:07 Joseph D. Wagner [this message]
-- strict thread matches above, loose matches on Subject: below --
2003-11-19 15:29 Pointer Woes: Pointer to a Pointer Joseph D. Wagner
2003-11-18 8:30 Joseph D. Wagner
2003-11-18 21:42 ` Glynn Clements
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200311190507.41687.theman@josephdwagner.info \
--to=theman@josephdwagner.info \
--cc=glynn.clements@virgin.net \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).