Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   calloc crashing -- dump core (http://www.velocityreviews.com/forums/t557194-calloc-crashing-dump-core.html)

Sheth Raxit 12-04-2007 09:06 AM

calloc crashing -- dump core
 
Hi

I am debugging multithreaded/netowrk prog code, It dumps core


hostname% gcc -v
Reading specs from /usr/local/lib/gcc-lib/sparc-sun-
solaris2.8/2.95.3/
specs
gcc version 2.95.3 20010315 (release)


icprg04% uname -a
SunOS <host> 5.10 Generic_118822-30 sun4u sparc SUNW,Sun-Fire-280R


====cut paste from dbx session this is ***dbx ./binary-name ./core
***
====
(dbx) thread t@65
Current function is get_remote_thick_profile
392 if (((*list) = (char *) calloc (1, sizeof (char))) ==
(char *)NULL)
t@65 (l@65) stopped in realfree at 0xff0d4834
0xff0d4834: realfree+0x00ec: st %l0, [%i0 + %o1]
(dbx) where
current thread: t@65
[1] realfree(0xf0628, 0x400, 0x93b28, 0x494e3240, 0x0, 0xf0a38), at
0xff0d4834
[2] cleanfree(0x0, 0x10, 0x93278, 0xff139980, 0xff168284,
0xff16fad4), at 0xff0d505c
[3] _malloc_unlocked(0x8, 0x18, 0xec398, 0xec3a0, 0xffffffff,
0xfefa1000), at 0xff0d41b4
[4] malloc(0x1, 0x1, 0x94224, 0xff16fa90, 0xff168284, 0xff1709b0),
at 0xff0d40a4
[5] calloc(0x1, 0x1, 0x1, 0xff139980, 0xfefa1000, 0x1000), at
0xff0c0e68
Other Function call


Interestingly Calloc is called as below ! and it is crashing.;
392 if (((*list) = (char *) calloc (1, sizeof (char))) ==
(char *)NULL)


What i guess is...


1. Definetly this calloc is not source of bug, but there MAY be
memory
corruption elsewhere.
2. Is this Bug ? ideally calloc should not crash :) like this way.
and
debugger should give me the source of real-error


--Raxit

jacob navia 12-04-2007 09:26 AM

Re: calloc crashing -- dump core
 
Sheth Raxit wrote:
> Hi
>
> I am debugging multithreaded/netowrk prog code, It dumps core
>
>
> hostname% gcc -v
> Reading specs from /usr/local/lib/gcc-lib/sparc-sun-
> solaris2.8/2.95.3/
> specs
> gcc version 2.95.3 20010315 (release)
>
>
> icprg04% uname -a
> SunOS <host> 5.10 Generic_118822-30 sun4u sparc SUNW,Sun-Fire-280R
>
>
> ====cut paste from dbx session this is ***dbx ./binary-name ./core
> ***
> ====
> (dbx) thread t@65
> Current function is get_remote_thick_profile
> 392 if (((*list) = (char *) calloc (1, sizeof (char))) ==
> (char *)NULL)


Look again at that. And if you do not find the bug you should write 100
times:

"I should look carefully at the code"

Good handwriting required!

P.S. calloc (1,sizeof(char)) allocates ONE character. Then it is cast
into a char POINTER, that is probably bigger than 1 character!!!

FIX:

if (((*list) = (char *) calloc (1, sizeof (char *))) ==(char *)NULL)
^

Note the char * instead of just char?


--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32

Laurent Deniau 12-04-2007 09:31 AM

Re: calloc crashing -- dump core
 
On 4 déc, 10:26, jacob navia <ja...@nospam.com> wrote:
> Sheth Raxit wrote:
> > Hi

>
> > I am debugging multithreaded/netowrk prog code, It dumps core

>
> > hostname% gcc -v
> > Reading specs from /usr/local/lib/gcc-lib/sparc-sun-
> > solaris2.8/2.95.3/
> > specs
> > gcc version 2.95.3 20010315 (release)

>
> > icprg04% uname -a
> > SunOS <host> 5.10 Generic_118822-30 sun4u sparc SUNW,Sun-Fire-280R

>
> > ====cut paste from dbx session this is ***dbx ./binary-name ./core
> > ***
> > ====
> > (dbx) thread t@65
> > Current function is get_remote_thick_profile
> > 392 if (((*list) = (char *) calloc (1, sizeof (char))) ==
> > (char *)NULL)

>
> Look again at that. And if you do not find the bug you should write 100
> times:
>
> "I should look carefully at the code"
>
> Good handwriting required!
>
> P.S. calloc (1,sizeof(char)) allocates ONE character. Then it is cast
> into a char POINTER,


which is right...

T* p = (T*) calloc(1, sizeof *T);

I suspect the problem to be elsewhere.

a+, ld.

jacob navia 12-04-2007 09:56 AM

Re: calloc crashing -- dump core
 
Laurent Deniau wrote:
> On 4 déc, 10:26, jacob navia <ja...@nospam.com> wrote:
>> Sheth Raxit wrote:
>>> Hi
>>> I am debugging multithreaded/netowrk prog code, It dumps core
>>> hostname% gcc -v
>>> Reading specs from /usr/local/lib/gcc-lib/sparc-sun-
>>> solaris2.8/2.95.3/
>>> specs
>>> gcc version 2.95.3 20010315 (release)
>>> icprg04% uname -a
>>> SunOS <host> 5.10 Generic_118822-30 sun4u sparc SUNW,Sun-Fire-280R
>>> ====cut paste from dbx session this is ***dbx ./binary-name ./core
>>> ***
>>> ====
>>> (dbx) thread t@65
>>> Current function is get_remote_thick_profile
>>> 392 if (((*list) = (char *) calloc (1, sizeof (char))) ==
>>> (char *)NULL)

>> Look again at that. And if you do not find the bug you should write 100
>> times:
>>
>> "I should look carefully at the code"
>>
>> Good handwriting required!
>>
>> P.S. calloc (1,sizeof(char)) allocates ONE character. Then it is cast
>> into a char POINTER,

>
> which is right...
>
> T* p = (T*) calloc(1, sizeof *T);
>
> I suspect the problem to be elsewhere.
>
> a+, ld.


There is no *T look again. There is only sizeof(char).

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32

Joachim Schmitz 12-04-2007 09:57 AM

Re: calloc crashing -- dump core
 
"Laurent Deniau" <Laurent.Deniau@gmail.com> schrieb im Newsbeitrag
news:df590acc-8d47-4294-9b66-444574de9f44@f3g2000hsg.googlegroups.com...
<snip>
>T* p = (T*) calloc(1, sizeof *T);

Drop the cast to not silence a possible compiler warning about a possibly
missing prototype

Bye, Jojo



Sheth Raxit 12-04-2007 10:01 AM

Re: calloc crashing -- dump core
 
On Dec 4, 2:26 pm, jacob navia <ja...@nospam.com> wrote:
> Sheth Raxit wrote:
> > Hi

>
> > I am debugging multithreaded/netowrk prog code, It dumps core

>
> > hostname% gcc -v
> > Reading specs from /usr/local/lib/gcc-lib/sparc-sun-
> > solaris2.8/2.95.3/
> > specs
> > gcc version 2.95.3 20010315 (release)

>
> > icprg04% uname -a
> > SunOS <host> 5.10 Generic_118822-30 sun4u sparc SUNW,Sun-Fire-280R

>
> > ====cut paste from dbx session this is ***dbx ./binary-name ./core
> > ***
> > ====
> > (dbx) thread t@65
> > Current function is get_remote_thick_profile
> > 392 if (((*list) = (char *) calloc (1, sizeof (char))) ==
> > (char *)NULL)

>
> Look again at that. And if you do not find the bug you should write 100
> times:
>
> "I should look carefully at the code"

I think i need to... :) , using for loop and printf. :) :)
>
> Good handwriting required!
>
> P.S. calloc (1,sizeof(char)) allocates ONE character. Then it is cast
> into a char POINTER, that is probably bigger than 1 character!!!

I am trying to allocating space for one character, and later i am
reallocating the same space.
>
> FIX:
>
> if (((*list) = (char *) calloc (1, sizeof (char *))) ==(char *)NULL)
> ^
>
> Note the char * instead of just char?

why sizeof(char *) ? return value is char* <which means pointing to
character>, which is still correct.

even we assume you are correct, why it is crashing. ?
>
> --
> jacob navia
> jacob at jacob point remcomp point fr
> logiciels/informatiquehttp://www.cs.virginia.edu/~lcc-win32- Hide quoted text -
>
> - Show quoted text -



Sheth Raxit 12-04-2007 10:11 AM

Re: calloc crashing -- dump core
 
On Dec 4, 2:56 pm, jacob navia <ja...@nospam.com> wrote:
> Laurent Deniau wrote:
> > On 4 déc, 10:26, jacob navia <ja...@nospam.com> wrote:
> >> Sheth Raxit wrote:
> >>> Hi
> >>> I am debugging multithreaded/netowrk prog code, It dumps core
> >>> hostname% gcc -v
> >>> Reading specs from /usr/local/lib/gcc-lib/sparc-sun-
> >>> solaris2.8/2.95.3/
> >>> specs
> >>> gcc version 2.95.3 20010315 (release)
> >>> icprg04% uname -a
> >>> SunOS <host> 5.10 Generic_118822-30 sun4u sparc SUNW,Sun-Fire-280R
> >>> ====cut paste from dbx session this is ***dbx ./binary-name ./core
> >>> ***
> >>> ====
> >>> (dbx) thread t@65
> >>> Current function is get_remote_thick_profile
> >>> 392 if (((*list) = (char *) calloc (1, sizeof (char))) ==
> >>> (char *)NULL)
> >> Look again at that. And if you do not find the bug you should write 100
> >> times:

>
> >> "I should look carefully at the code"

>
> >> Good handwriting required!

>
> >> P.S. calloc (1,sizeof(char)) allocates ONE character. Then it is cast
> >> into a char POINTER,

>
> > which is right...

>
> > T* p = (T*) calloc(1, sizeof *T);

>
> > I suspect the problem to be elsewhere.

>
> > a+, ld.

>
> There is no *T look again. There is only sizeof(char).

actually list is passed as char **list in the function.

int f1(char **list)
{
...
...

if (((*list) = (char *) calloc (1, sizeof (char))) ==(char *)NULL)
...
...
}

>
> --
> jacob navia
> jacob at jacob point remcomp point fr
> logiciels/informatiquehttp://www.cs.virginia.edu/~lcc-win32- Hide quoted text -
>
> - Show quoted text -



Richard Heathfield 12-04-2007 10:11 AM

Re: calloc crashing -- dump core
 
Sheth Raxit said:

<snip>

> Interestingly Calloc is called as below ! and it is crashing.;
> 392 if (((*list) = (char *) calloc (1, sizeof (char))) ==
> (char *)NULL)


You might find this easier to read if you write it as:

*list = calloc(1, 1);
if(*list == NULL)
{

Incidentally, does this re-write suggest anything to you about the amount
of storage you're allocating?

> What i guess is...


Guessing isn't going to help you. What is the value of list before this
allocation? Does it point to an existing char * object? If not,
dereferencing it (as you do here) is asking for trouble.


> 1. Definetly this calloc is not source of bug, but there MAY be
> memory
> corruption elsewhere.
> 2. Is this Bug ? ideally calloc should not crash :) like this way.
> and
> debugger should give me the source of real-error


Debuggers are not mind-readers. They're more like torches (flashlights).
They can shine a light beam for you, but it is up to you to point it in
the direction you want to see.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999

vippstar@gmail.com 12-04-2007 10:47 AM

Re: calloc crashing -- dump core
 
On Dec 4, 12:11 pm, Sheth Raxit <raxitsheth2...@gmail.com> wrote:
> On Dec 4, 2:56 pm, jacob navia <ja...@nospam.com> wrote:
>
> > Laurent Deniau wrote:
> > > On 4 déc, 10:26, jacob navia <ja...@nospam.com> wrote:
> > >> Sheth Raxit wrote:
> > >>> Hi
> > >>> I am debugging multithreaded/netowrk prog code, It dumps core
> > >>> hostname% gcc -v
> > >>> Reading specs from /usr/local/lib/gcc-lib/sparc-sun-
> > >>> solaris2.8/2.95.3/
> > >>> specs
> > >>> gcc version 2.95.3 20010315 (release)
> > >>> icprg04% uname -a
> > >>> SunOS <host> 5.10 Generic_118822-30 sun4u sparc SUNW,Sun-Fire-280R
> > >>> ====cut paste from dbx session this is ***dbx ./binary-name ../core
> > >>> ***
> > >>> ====
> > >>> (dbx) thread t@65
> > >>> Current function is get_remote_thick_profile
> > >>> 392 if (((*list) = (char *) calloc (1, sizeof (char))) ==
> > >>> (char *)NULL)
> > >> Look again at that. And if you do not find the bug you should write 100
> > >> times:

>
> > >> "I should look carefully at the code"

>
> > >> Good handwriting required!

>
> > >> P.S. calloc (1,sizeof(char)) allocates ONE character. Then it is cast
> > >> into a char POINTER,

>
> > > which is right...

>
> > > T* p = (T*) calloc(1, sizeof *T);

>
> > > I suspect the problem to be elsewhere.

>
> > > a+, ld.

>
> > There is no *T look again. There is only sizeof(char).

>
> actually list is passed as char **list in the function.
>
> int f1(char **list)
> {
> ...
> ...
>
> if (((*list) = (char *) calloc (1, sizeof (char))) ==(char *)NULL)
> ...
> ...
>
> }


Please post a minimal test case that demonstrates your problem.

That function could be valid if used like this:
--
char *p;
f1(&p);
--
But invalid if used like this
--
char **p;
f1(p);
--

Also, decide what language you're using, and if you find the problem
to be somewhere outside of standard C code post in an appropriate
newsgroup

Laurent Deniau 12-04-2007 11:11 AM

Re: calloc crashing -- dump core
 
On 4 déc, 10:56, jacob navia <ja...@nospam.com> wrote:
> Laurent Deniau wrote:
> > On 4 déc, 10:26, jacob navia <ja...@nospam.com> wrote:
> >> Sheth Raxit wrote:
> >>> Hi
> >>> I am debugging multithreaded/netowrk prog code, It dumps core
> >>> hostname% gcc -v
> >>> Reading specs from /usr/local/lib/gcc-lib/sparc-sun-
> >>> solaris2.8/2.95.3/
> >>> specs
> >>> gcc version 2.95.3 20010315 (release)
> >>> icprg04% uname -a
> >>> SunOS <host> 5.10 Generic_118822-30 sun4u sparc SUNW,Sun-Fire-280R
> >>> ====cut paste from dbx session this is ***dbx ./binary-name ./core
> >>> ***
> >>> ====
> >>> (dbx) thread t@65
> >>> Current function is get_remote_thick_profile
> >>> 392 if (((*list) = (char *) calloc (1, sizeof (char))) ==
> >>> (char *)NULL)
> >> Look again at that. And if you do not find the bug you should write 100
> >> times:

>
> >> "I should look carefully at the code"

>
> >> Good handwriting required!

>
> >> P.S. calloc (1,sizeof(char)) allocates ONE character. Then it is cast
> >> into a char POINTER,

>
> > which is right...

>
> > T* p = (T*) calloc(1, sizeof *T);


oups:

T* p = (T*) calloc(1, sizeof *p);

> > I suspect the problem to be elsewhere.

>
> > a+, ld.

>
> There is no *T look again. There is only sizeof(char).


s/\*T/\*p/

still, if T is char, *p is of type char, then sizeof(char) is ok.

a+, ld.


All times are GMT. The time now is 05:15 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.