public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Trouble with realloc
@ 2003-10-15 12:54 Joseph D. Wagner
  0 siblings, 0 replies; 2+ messages in thread
From: Joseph D. Wagner @ 2003-10-15 12:54 UTC (permalink / raw)
  To: gcc-help

I know this is a stupid, simple problem, and the answer is staring me right 
in the face, but I can't see it.  I know you're going to laugh at me the 
moment you're done reading this email, but please help me just the same.

I keep getting a segmentation fault on realloc.

I've tried every combination of * and & that I can think of, but nothing 
helps.

struct block_order_log_t
{
    e2_blkcnt_t totalBlocks;
    blk_t *blockID;
};

...

struct ext2_inode inode;
struct block_order_log_t block_order_log;

...

block_order_log.blockID = (blk_t*) calloc(inode.i_blocks,
    sizeof(struct block_order_log_t));

...

/* Allocates more memory for the log if needed */
if(inode.i_blocks > block_order_log.totalBlocks)
{
    /* The problem is here */
    block_order_log.blockID = (blk_t*) realloc(block_order_log.blockID,
        sizeof(struct block_order_log_t) * inode.i_blocks);
}

TIA.

Joseph D. Wagner

---------------------------------------------------------------------

"Introducing Microsoft Windows 2003 Server.  Do more with less."
                                               -- MS Sales Motto

"Do more with less"?  Are you saying Windows 2003 is less?

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

* Re: Trouble with realloc
       [not found] <001501c3931e$c41ad2a0$5b02000a@solipsys.com>
@ 2003-10-15 17:28 ` Joseph D. Wagner
  0 siblings, 0 replies; 2+ messages in thread
From: Joseph D. Wagner @ 2003-10-15 17:28 UTC (permalink / raw)
  To: Tony Wetmore; +Cc: gcc-help

Boy, do I feel stupid.

Thanks, that was the problem exactly, just needed a fresh pair of eyes.

On Wednesday 15 October 2003 07:18 pm, Tony Wetmore wrote:
> Joseph,
>
> When allocating (or re-allocating) memory for block_order_log.blockID,
> you allocate memory based on the size of the block_order_log_t
> structure, even though blockID points to type blk_t.  I do not know if
> that is correct behavior, or if it might be at the heart of your
> problem.
>
> If your intent is to store an array of blk_t objects pointed to by
> blockID, this could very well be your problem, unless a blk_t is
> essentially an alias for block_order_log_t.
>
> Hope this helps!
>
> ---
> Tony Wetmore
> Raytheon Solipsys
> mailto:tony.wetmore@solipsys.com
> http://www.solipsys.com
>
>
>
>
> -----Original Message-----
> From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On
> Behalf Of Joseph D. Wagner
> Sent: Tuesday, October 14, 2003 9:54 PM
> To: gcc-help@gcc.gnu.org
> Subject: Trouble with realloc
>
>
> I know this is a stupid, simple problem, and the answer is staring me
> right
> in the face, but I can't see it.  I know you're going to laugh at me the
>
> moment you're done reading this email, but please help me just the same.
>
> I keep getting a segmentation fault on realloc.
>
> I've tried every combination of * and & that I can think of, but nothing
>
> helps.
>
> struct block_order_log_t
> {
>     e2_blkcnt_t totalBlocks;
>     blk_t *blockID;
> };
>
> ...
>
> struct ext2_inode inode;
> struct block_order_log_t block_order_log;
>
> ...
>
> block_order_log.blockID = (blk_t*) calloc(inode.i_blocks,
>     sizeof(struct block_order_log_t));
>
> ...
>
> /* Allocates more memory for the log if needed */ if(inode.i_blocks >
> block_order_log.totalBlocks) {
>     /* The problem is here */
>     block_order_log.blockID = (blk_t*) realloc(block_order_log.blockID,
>         sizeof(struct block_order_log_t) * inode.i_blocks);
> }
>
> TIA.
>
> Joseph D. Wagner
>
> ---------------------------------------------------------------------
>
> "Introducing Microsoft Windows 2003 Server.  Do more with less."
>                                                -- MS Sales Motto
>
> "Do more with less"?  Are you saying Windows 2003 is less?

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

end of thread, other threads:[~2003-10-15 17:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-15 12:54 Trouble with realloc Joseph D. Wagner
     [not found] <001501c3931e$c41ad2a0$5b02000a@solipsys.com>
2003-10-15 17:28 ` Joseph D. Wagner

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 read-only IMAP folder(s) and NNTP newsgroup(s).