public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* coredump
@ 2001-03-17  4:20 Puneet Singhal
  2001-03-17  7:42 ` coredump Soubhik Bhattacharya
  0 siblings, 1 reply; 6+ messages in thread
From: Puneet Singhal @ 2001-03-17  4:20 UTC (permalink / raw)
  To: gcc-help

Hi all

I compiled a program on linked lists using gcc


Here is a snapshot of the code...

1.          pBind->pNext = (PLLBIND)( (char *)pBind + usTrueAtomSize );
2.          (pBind->pNext)->pPrev = pBind;
3.          pBind = pBind->pNext;

statement no 2 is giving core.

pBind or pNext is Not NULL.

can anyone tell me why??

Also are there any good containers written in C available on the net.

TIA,
Puneet


*********************************************
The Boulder Pledge: "Under no circumstances will I ever purchase anything
offered to me as the result of an unsolicited email message. Nor will I
forward chain letters, petitions, mass mailings, or virus warnings to large
numbers of others. This is my contribution to the survival of the online
community."
*********************************************
Those who do not understand Unix are condemned to reinvent it, poorly.
                -- Henry Spencer
Unix is user-friendly (it only choose its friends carefully)

----------------------------------------------------------------------------
----



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

* Re: coredump
  2001-03-17  4:20 coredump Puneet Singhal
@ 2001-03-17  7:42 ` Soubhik Bhattacharya
  0 siblings, 0 replies; 6+ messages in thread
From: Soubhik Bhattacharya @ 2001-03-17  7:42 UTC (permalink / raw)
  To: Puneet Singhal; +Cc: gcc-help

:
:Here is a snapshot of the code...
:
:1.          pBind->pNext = (PLLBIND)( (char *)pBind + usTrueAtomSize );
:2.          (pBind->pNext)->pPrev = pBind;
:3.          pBind = pBind->pNext;
:
:statement no 2 is giving core.
:
:pBind or pNext is Not NULL.
:

alignment problem?? are you sure that (pBind->pNext) is properly aligned
for PLLBIND, after execution of stmt 1 ?

--soubhik.

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

* Re: Coredump
  2000-12-13 20:56   ` Coredump Puneet Singhal
@ 2000-12-14  8:12     ` Alexandre Oliva
  0 siblings, 0 replies; 6+ messages in thread
From: Alexandre Oliva @ 2000-12-14  8:12 UTC (permalink / raw)
  To: Puneet Singhal; +Cc: Gcchelp

On Dec 14, 2000, "Puneet Singhal" <puneet@opussoft.com> wrote:

> The same code works fine on NCR UNIX

It works fine on all systems.  It's just a matter of defining `fine'.
The code invokes undefined behavior, so the run-time library is
entitled to do anything at all.  It might have formatted your hard
disk as well :-)

> When we port the same code to Solaris Sparc it gives a core dump why??

Because printf() ends up dereferencing the NULL pointer you passed to
it.  It might have checked whether the given pointer was NULL, but
then every single printf() of a string would incur this cost.  Why
impose this cost upon everybody, given that NULL isn't a valid string
anyway?

Besides, by having the program crash at that point, you can easily
figure out where the problem is from the stack trace you can get from
the core file, and fix it.  If printf just printed some odd string,
you'd have far more trouble figuring out which statement in your
program makes the invalid printf call.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me

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

* RE: Coredump
  2000-12-13 12:40 ` Coredump Alexandre Oliva
@ 2000-12-13 20:56   ` Puneet Singhal
  2000-12-14  8:12     ` Coredump Alexandre Oliva
  0 siblings, 1 reply; 6+ messages in thread
From: Puneet Singhal @ 2000-12-13 20:56 UTC (permalink / raw)
  To: Gcchelp

The same code works fine on NCR UNIX
When we port the same code to Solaris Sparc it gives a core dump why??


-----Original Message-----
From: gcc-help-owner@gcc.gnu.org [ mailto:gcc-help-owner@gcc.gnu.org]On
Behalf Of Alexandre Oliva
Sent: Wednesday, December 13, 2000 12:40 PM
To: Puneet Singhal
Cc: Gcchelp
Subject: Re: Coredump


On Dec 13, 2000, "Puneet Singhal" <puneet@opussoft.com> wrote:

> 	char *p=NULL;
> 	printf("%s", p);

> I get a coredump at runtime.

What did you expect?  You tell it to print a NUL-terminated string,
and don't give it a string at all.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me

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

* Re: Coredump
  2000-12-13  3:06 Coredump Puneet Singhal
@ 2000-12-13 12:40 ` Alexandre Oliva
  2000-12-13 20:56   ` Coredump Puneet Singhal
  0 siblings, 1 reply; 6+ messages in thread
From: Alexandre Oliva @ 2000-12-13 12:40 UTC (permalink / raw)
  To: Puneet Singhal; +Cc: Gcchelp

On Dec 13, 2000, "Puneet Singhal" <puneet@opussoft.com> wrote:

> 	char *p=NULL;
> 	printf("%s", p);

> I get a coredump at runtime.

What did you expect?  You tell it to print a NUL-terminated string,
and don't give it a string at all.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me

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

* Coredump
@ 2000-12-13  3:06 Puneet Singhal
  2000-12-13 12:40 ` Coredump Alexandre Oliva
  0 siblings, 1 reply; 6+ messages in thread
From: Puneet Singhal @ 2000-12-13  3:06 UTC (permalink / raw)
  To: Gcchelp

Hi
I am compiling and linking the foll code with gcc-2.95.2 on Solaris 7 on
sparc.

int main()
{
	char *p=NULL;
	printf("%s", p);
	return 0;
}

I get a coredump at runtime. Please help..

I tried using the flag -fno-delete-null-pointer-checks for optimization but
gcc does not recognize this flag and gives an error.

Please Help!!

thanx
Puneet


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

end of thread, other threads:[~2001-03-17  7:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-17  4:20 coredump Puneet Singhal
2001-03-17  7:42 ` coredump Soubhik Bhattacharya
  -- strict thread matches above, loose matches on Subject: below --
2000-12-13  3:06 Coredump Puneet Singhal
2000-12-13 12:40 ` Coredump Alexandre Oliva
2000-12-13 20:56   ` Coredump Puneet Singhal
2000-12-14  8:12     ` Coredump Alexandre Oliva

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