www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/06/23/11:00:18

From: "Matt Bayliss" <grebz AT hiddenemail DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Memory troubles.
Date: Sat, 23 Jun 2001 16:00:21 +0100
Organization: (Posted via) GTS Netcom - Public USENET Service http://pubnews.netcom.net.uk
Lines: 36
Sender: grebz AT crosswinds DOT net
Message-ID: <9h2arg$54v$1@taliesin.netcom.net.uk>
NNTP-Posting-Host: host62-7-83-77.btinternet.com
X-Trace: taliesin.netcom.net.uk 993308337 5279 62.7.83.77 (23 Jun 2001 14:58:57 GMT)
X-Complaints-To: abuse AT corp DOT netcom DOT net DOT uk
NNTP-Posting-Date: Sat, 23 Jun 2001 14:58:57 +0000 (UTC)
X-Newsreader: Microsoft Outlook Express 4.72.3110.1
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

HI There,

I'm having some trouble with the following statement:

// ***
HitCounter++; // Makes it 1 at this point.
DataCounter = 1;
   while ( Data[DataCounter] != NULL )
   {
    if ( ( newpointer = realloc( *value_p_p, (sizeof(int)) * (HitCounter +
1) ) ) != NULL )    {
     *value_p_p = newpointer;
     *value_p_p[HitCounter] = Data[DataCounter];
     HitCounter++;
     DataCounter++;
    }
   }
// ***

value_p_p is passed to the function this statement is in with myfunc( int
**value_p_p ).  It is declared the same type in the calling function.
When the while() has looped twice (when the HitCounter reaches 3), the next
call to realloc(), which the expression (sizeof(int) * (HitCounter+1)
equates to 16 bytes returns a pointer as though the call has suceeded.
However, when I try to access the 4th byte with *value_p_p[3] I get "cannot
access memory at address 0x1" reported by gdb.
I can access all the "earlier" ones with *value_p_p[0], *value_p_p[1] etc.
Why then did the call to realloc() succeed?

Please help,

Matt




- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019