delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2000/06/22/09:22:07

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: <E5C79049D461D311B83100062950B54A2FB085@nt-stoc-0.sbs>
From: Mike Little <M DOT Little AT servicepower DOT com>
To: "'Marco DOT Pettinella AT marconi DOT com'" <Marco DOT Pettinella AT marconi DOT com>,
cygwin AT sourceware DOT cygnus DOT com
Subject: RE: Unexpected stack dump using strtok() function
Date: Thu, 22 Jun 2000 14:20:48 +0100
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2650.21)

> -----Original Message-----
> From: Marco DOT Pettinella AT marconi DOT com 
> [mailto:Marco DOT Pettinella AT marconi DOT com]
> Sent: Thursday, June 22, 2000 1:57 PM
> To: cygwin AT sourceware DOT cygnus DOT com
> Subject: Unexpected stack dump using strtok() function
> 
> 
> 
> 
> Hi everybody.
> I've just installed Cygwin 1.1.2 (uname -r : 1.1.2(0.21/3/2) ).
> 
> I'm doing some tests finalized to port a Unix application 
> under Windows NT.
> 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);
>      if (name == NULL) {
>           fprintf (stderr, "NAME IS NULL!\n");
>           return -1;
>      }
>      fprintf (stderr, "NAME: %s\n", name);
> 
>      surname = strtok (0, separator);
>      if (surname == NULL) {
>           fprintf (stderr, "SURNAME IS NULL!\n");
>           return -1;
>      }
>      fprintf (stderr, "SURNAME: %s\n", surname);
> 
>      return 0;
> }
> 
> I also compiled this program under SCO Unix and HP UX, and I 
> verified that
> it runs correctly, as expected.
> 
> I'm wondering if this SIGSEGV is due to a misconfiguration of 
> my gcc or if it is
>  a bug.
> Does anybody have experienced a problem like this?
> 
> My release of gcc is 2.95.2-1.
> 
> Thanks in advance for your help. Marco

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.
2) Did you try looking at the stack trace? It should show which bit of your
code,
   was being executed when the signal was received.	


Also, which gcc options are you using?


Hope this helps,
Mike

--
Mike Little
Share what you know. Learn what you don't.

ServicePOWER Business Solutions Ltd
home: mike AT ampersoft DOT co DOT uk

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