Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , 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" Reply-To: "13mb80000-HallM(10053584)37x10" 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 Content-Type: text 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 > > #include > > #include > > > > 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