delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2000/06/22/11:42:45

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sourceware DOT cygnus DOT com>
List-Archive: <http://sourceware.cygnus.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sourceware DOT cygnus DOT com>
List-Help: <mailto:cygwin-help AT sourceware DOT cygnus DOT com>, <http://sourceware.cygnus.com/ml/#faqs>
Sender: cygwin-owner AT sourceware DOT cygnus DOT com
Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com
Message-Id: <200006221541.JAA11457@chorus>
Date: Thu, 22 Jun 2000 09:41:29 -0600 (MDT)
From: "13mb80000-HallM(10053584)37x10" <marcus AT bighorn DOT dr DOT lucent DOT com>
Reply-To: "13mb80000-HallM(10053584)37x10" <marcus AT bighorn DOT dr DOT lucent DOT com>
Subject: RE: Unexpected stack dump using strtok() function
To: Marco DOT Pettinella AT marconi DOT com, cygwin AT sourceware DOT cygnus DOT com
X-Mailer: dtmail 1.2.1 CDE Version 1.2.1 SunOS 5.6 sun4m sparc
X-Sun-Text-Type: ascii


> > I noted that, while using strtok() function, I receive a SIGSEGV
> > which causes a stack dump under NT.
> > 
> > The little program I used to understand this behaviour was 
> > the following:
> > 
> > #include <stdio.h>
> > #include <string.h>
> > #include <stdlib.h>
> > 
> > int
> > main()
> > {
> >      static char *string = "MARCO#PETTINELLA";
> >      static char *separator = "#";
> >      char *name;
> >      char *surname;
> > 
> >      name = NULL;
> >      surname = NULL;
> > 
> >      name = strtok (string, separator);

...

> A couple of thoughts:
> 1) The literal 'string' ought to be in a read-only data area.
>    So the sigsegv could come from strtok trying to write a 0 over the first
> hash.
>    Not all compilers/OS's support such a concept, so it may not show up 
>    in different implementations.

Yes, it almost certainly is that the string is being placed into read-only
as it should unless you give gcc the -fwritable-strings option.  Note, that
a small change to this program can make it very portable:

Change:
	static char *string = 
to:
	static char string[] = "MARCO#PETTINELLA";

Then, string will not be a pointer to the read-only string "MARCO#PETTINELLA",
but will be a 17 character array initialized to MARCO#PETTINELLA\0.  Since
it is then initialized data instead of a string constant, it will be
writable in all implementations.

marcus

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019