SIGSEGV in new/malloc
Arno Wilhelm
arno.wilhelm@profile.co.at
Wed Sep 15 12:05:00 GMT 2004
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
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: arno.wilhelm.vcf
Type: text/x-vcard
Size: 189 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20040915/e29f8bf9/attachment-0001.vcf>
More information about the Gcc-help
mailing list