linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: "Jerry Quinn" <jquinn@nortelnetworks.com>
To: Alain Birtz <abz@videotron.ca>
Cc: linuxppc-dev@lists.linuxppc.org
Subject: Realloc() problem with Efence
Date: Wed, 28 Jul 1999 16:54:35 -0400 (EDT)	[thread overview]
Message-ID: <14239.28171.5732.716574@gargle.gargle.HOWL> (raw)
In-Reply-To: <379F7AB9.E8D230CE@videotron.ca>



Alain Birtz <abz@videotron.ca> writes:
Alain> What is wrong with this code ?
Alain> Code is executed correctly without Electric Fence
Alain> But linked with Efence library, dbg complaint:
Alain> 
Alain> 	  Electric Fence 2.0.5 Copyright (C) 1987-1998 Bruce Perens.
Alain> 	  ...
Alain> 	  ...
Alain> 	  Program received signal SIGSEGV, Segmentation fault.
Alain> 
Alain> when trying to write the first B, just after the first memory allocation
Alain> buffer
Alain> (at the instruction (*c_ptr++ = 'B'))
Alain> 
Alain> 
Alain> void tst ()
Alain> {
Alain> 	int i;
Alain> 	char *c_buf, *c_ptr, *temp_c_buf;
Alain> 
Alain> 	c_buf = (char *)malloc(5000);
Alain> 	if (c_buf != NULL)
Alain> 	 {
Alain> 	 c_ptr = c_buf;
Alain> 	 for (i = 0; i < 5000; i++)
Alain> 	  *c_ptr++ = 'A';
Alain> 	 temp_c_buf = c_buf;
Alain> 	 realloc(temp_c_buf, 5000 + 5000);
Alain> 	 if (temp_c_buf != NULL)
Alain> 	  {
Alain> 	  for (i = 0; i < 5000; i++)
Alain> 	   *c_ptr++ = 'B';
Alain> 	  }
Alain> 	 }
Alain> }
Alain> 

realloc can (and did) move the block.  Therefore, when you start writing 'B's, 
they are going into invalid memory.  The fact that it works without Electric
Fence is luck.

To do this, you need to set the pointer to the whole block to the output of
realloc and then you can start writing B's at the new location + 5000.

-- 
Jerry Quinn                             Tel: (514) 761-8737
jquinn@nortelnetworks.com               Fax: (514) 761-8505
Speech Recognition Research


[[ This message was sent via the linuxppc-dev mailing list.  Replies are ]]
[[ not  forced  back  to the list, so be sure to Cc linuxppc-dev if your ]]
[[ reply is of general interest. Please check http://lists.linuxppc.org/ ]]
[[ and http://www.linuxppc.org/ for useful information before posting.   ]]

      parent reply	other threads:[~1999-07-28 20:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-07-28 21:48 Realloc() problem with Efence Alain Birtz
1999-07-28 20:03 ` Nicholas T Ingolia
1999-07-28 20:54 ` Jerry Quinn [this message]

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=14239.28171.5732.716574@gargle.gargle.HOWL \
    --to=jquinn@nortelnetworks.com \
    --cc=abz@videotron.ca \
    --cc=linuxppc-dev@lists.linuxppc.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).