public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* SIGSEGV in new/malloc
@ 2004-09-15 11:14 Karthik J
  2004-09-15 12:05 ` Arno Wilhelm
  2004-09-15 12:13 ` Eljay Love-Jensen
  0 siblings, 2 replies; 5+ messages in thread
From: Karthik J @ 2004-09-15 11:14 UTC (permalink / raw)
  To: gcc

Hi,

	I am using g++ version 2.95.2. The following code crashes
intermittently 

	typedef unsigned char	BYTE;
	int nNewSize = 1;

	void** m_pData = ( void ** ) new BYTE[ nNewSize * sizeof( BYTE *
) ];

Back trace on gdb does not give me the lib where it crashes



Then, I tried this,

		void** m_pData = ( void ** )malloc( nNewSize * sizeof(
void * ) );

	and even 

		void** m_pData = ( void ** )malloc( 4 );

But it always gives a SIGSEGV. bt from gdb in this case gives

#0 in _smalloc() from /usr/lib/libc.so.1
#1 in malloc() from /usr/lib/libc.so.1


What am I doing wrong? Have I run out of virtual memory for malloc to
crash?

TIA,

Kartik

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

* Re: SIGSEGV in new/malloc
  2004-09-15 11:14 SIGSEGV in new/malloc Karthik J
@ 2004-09-15 12:05 ` Arno Wilhelm
  2004-09-15 12:13 ` Eljay Love-Jensen
  1 sibling, 0 replies; 5+ messages in thread
From: Arno Wilhelm @ 2004-09-15 12:05 UTC (permalink / raw)
  Cc: gcc

[-- Attachment #1: Type: text/plain, Size: 1247 bytes --]

hi,

when I compile and run the following code it does *not* crash on my machine:


1
2 int main(void)
3 {
4 typedef unsigned char   BYTE;
5 int nNewSize = 1;
6
7      void** m_pData = ( void ** ) new BYTE[ nNewSize * sizeof( BYTE *) ];
8
9 return 0;
10 }
11

So I assume that it crashes when you *use* the void** m_pData pointer?


I also do not understand why you declare (and cast) the m_pData pointer to 
void** since new and malloc return a void* pointer.
Maybe that is the reason why it crashes ?


cheers,

Arno




> Hi,
> 
> 	I am using g++ version 2.95.2. The following code crashes
> intermittently 
> 
> 	typedef unsigned char	BYTE;
> 	int nNewSize = 1;
> 
> 	void** m_pData = ( void ** ) new BYTE[ nNewSize * sizeof( BYTE *
> ) ];
> 
> Back trace on gdb does not give me the lib where it crashes
> 
> 
> 
> Then, I tried this,
> 
> 		void** m_pData = ( void ** )malloc( nNewSize * sizeof(
> void * ) );
> 
> 	and even 
> 
> 		void** m_pData = ( void ** )malloc( 4 );
> 
> But it always gives a SIGSEGV. bt from gdb in this case gives
> 
> #0 in _smalloc() from /usr/lib/libc.so.1
> #1 in malloc() from /usr/lib/libc.so.1
> 
> 
> What am I doing wrong? Have I run out of virtual memory for malloc to
> crash?
> 
> TIA,
> 
> Kartik
> 


[-- Attachment #2: arno.wilhelm.vcf --]
[-- Type: text/x-vcard, Size: 189 bytes --]

begin:vcard
fn:Arno Wilhelm
n:Wilhelm;Arno
org:proFILE Computersysteme GmbH
email;internet:arno.wilhelm@profile.co.at
tel;work:+43 512 341934 29
x-mozilla-html:FALSE
version:2.1
end:vcard


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

* Re: SIGSEGV in new/malloc
  2004-09-15 11:14 SIGSEGV in new/malloc Karthik J
  2004-09-15 12:05 ` Arno Wilhelm
@ 2004-09-15 12:13 ` Eljay Love-Jensen
  1 sibling, 0 replies; 5+ messages in thread
From: Eljay Love-Jensen @ 2004-09-15 12:13 UTC (permalink / raw)
  To: Karthik J, gcc

Hi Karthik,

Sorry, I could not get this to crash...
int main()
{
     typedef unsigned char BYTE;
     int nNewSize = 1;

     void** m_pData = (void**) new BYTE[nNewSize * sizeof(BYTE*)];
}

What compiler flags are you using?

What OS are you using?

Does your program do anything more than the above, or is this the smallest 
program that reproduces the problem for you?

You could do this, by the way...
void** m_pData = new void*;
...cuts out some array voodoo magic sizing monkey business.  But that 
shouldn't have any impact on your problem.  Just a coding style suggestion.

--Eljay

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

* RE: SIGSEGV in new/malloc
@ 2004-09-15 13:03 Karthik J
  0 siblings, 0 replies; 5+ messages in thread
From: Karthik J @ 2004-09-15 13:03 UTC (permalink / raw)
  To: Eljay Love-Jensen, gcc

Hi Eljay,

	Thanks for your response.
	
	Actually there are lots of succesfull calls to new/malloc,
before I run into this error.
	m_pData  is a member of a class, which essentially describes an
array of pointers( of any type, hence void** ). When I initially try to
set the size of the array( to some value that's nNewSize ), I allocate
memory to this array. That's when the crash occurs! 

	Compiler flags are -> -pipe -g -fPIC -Wall -Wno-reorder
	OS -> Solaris 8

	I am cutting out on all the voodoo for now and wrapping around a
std::vector< void* > instead:-).

	Thanks again.

-Kartik
	

-----Original Message-----
From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On
Behalf Of Eljay Love-Jensen
Sent: Wednesday, September 15, 2004 5:43 PM
To: Karthik J; gcc
Subject: Re: SIGSEGV in new/malloc

Hi Karthik,

Sorry, I could not get this to crash...
int main()
{
     typedef unsigned char BYTE;
     int nNewSize = 1;

     void** m_pData = (void**) new BYTE[nNewSize * sizeof(BYTE*)]; }

What compiler flags are you using?

What OS are you using?

Does your program do anything more than the above, or is this the
smallest program that reproduces the problem for you?

You could do this, by the way...
void** m_pData = new void*;
...cuts out some array voodoo magic sizing monkey business.  But that
shouldn't have any impact on your problem.  Just a coding style
suggestion.

--Eljay



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

* RE: SIGSEGV in new/malloc
@ 2004-09-15 12:10 Karthik J
  0 siblings, 0 replies; 5+ messages in thread
From: Karthik J @ 2004-09-15 12:10 UTC (permalink / raw)
  To: Arno Wilhelm; +Cc: gcc

Hi Arno,

	Thanks for your reply.
	Actually, it crashes during the call to 'new' or 'malloc', like
I said in libc.so.1.

	Since it is an array of void*, I have to allocate a void**. 

Thanks,

Kartik

-----Original Message-----
From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On
Behalf Of Arno Wilhelm
Sent: Wednesday, September 15, 2004 5:35 PM
Cc: gcc
Subject: Re: SIGSEGV in new/malloc

hi,

when I compile and run the following code it does *not* crash on my
machine:


1
2 int main(void)
3 {
4 typedef unsigned char   BYTE;
5 int nNewSize = 1;
6
7      void** m_pData = ( void ** ) new BYTE[ nNewSize * sizeof( BYTE *)
];
8
9 return 0;
10 }
11

So I assume that it crashes when you *use* the void** m_pData pointer?


I also do not understand why you declare (and cast) the m_pData pointer
to
void** since new and malloc return a void* pointer.
Maybe that is the reason why it crashes ?


cheers,

Arno




> Hi,
> 
> 	I am using g++ version 2.95.2. The following code crashes
> intermittently 
> 
> 	typedef unsigned char	BYTE;
> 	int nNewSize = 1;
> 
> 	void** m_pData = ( void ** ) new BYTE[ nNewSize * sizeof( BYTE *
> ) ];
> 
> Back trace on gdb does not give me the lib where it crashes
> 
> 
> 
> Then, I tried this,
> 
> 		void** m_pData = ( void ** )malloc( nNewSize * sizeof(
> void * ) );
> 
> 	and even 
> 
> 		void** m_pData = ( void ** )malloc( 4 );
> 
> But it always gives a SIGSEGV. bt from gdb in this case gives
> 
> #0 in _smalloc() from /usr/lib/libc.so.1
> #1 in malloc() from /usr/lib/libc.so.1
> 
> 
> What am I doing wrong? Have I run out of virtual memory for malloc to
> crash?
> 
> TIA,
> 
> Kartik
> 



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

end of thread, other threads:[~2004-09-15 13:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-15 11:14 SIGSEGV in new/malloc Karthik J
2004-09-15 12:05 ` Arno Wilhelm
2004-09-15 12:13 ` Eljay Love-Jensen
2004-09-15 12:10 Karthik J
2004-09-15 13:03 Karthik J

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).