From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17640 invoked by alias); 26 Feb 2003 05:46:01 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 17554 invoked by uid 71); 26 Feb 2003 05:46:01 -0000 Resent-Date: 26 Feb 2003 05:46:01 -0000 Resent-Message-ID: <20030226054601.17553.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, ocmbah@unity.ncsu.edu Received: (qmail 17182 invoked by uid 48); 26 Feb 2003 05:43:51 -0000 Message-Id: <20030226054351.17181.qmail@sources.redhat.com> Date: Wed, 26 Feb 2003 05:46:00 -0000 From: ocmbah@unity.ncsu.edu Reply-To: ocmbah@unity.ncsu.edu To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version: gnatsweb-2.9.3 (1.1.1.1.2.31) Subject: c/9857: string tokenizer causes segmentation faults X-SW-Source: 2003-02/txt/msg01358.txt.bz2 List-Id: >Number: 9857 >Category: c >Synopsis: string tokenizer causes segmentation faults >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: sw-bug >Submitter-Id: net >Arrival-Date: Wed Feb 26 05:46:01 UTC 2003 >Closed-Date: >Last-Modified: >Originator: ocmbah@unity.ncsu.edu >Release: gcc version 2.96 20000731 (Red Hat Linux 7.3 2.96-110) >Organization: >Environment: red hate 7.3 >Description: i noticed some strange behavior with using the strtok() function, it worked normally into my program until i got the bright idea of making a function out of some duplicate code and it mysteriously caused strtok to seg fault even though the functions that i made don't call it i tried to reproduce this on a smaller scale w/o sending you my program so here's what i came up with, i didn't think this was going to seg fault at all but it did so... #include #include #define DELIMS " \t\n" typedef struct { char uin[9]; /* User ID */ char last[20]; /* Last name */ char first[15]; /* First name */ int grades[6]; /* List of student's 6 grades */ float average; /* Student's average */ } studentRecord; int main(void) { int i; studentRecord *stuRec; char *string = "jdoe\tDoe\tJohn\t98\t90\t87\t88\t86\t82\t88.5"; stuRec = (studentRecord *) malloc(sizeof(studentRecord)); strcpy(stuRec->uin, strtok(string, DELIMS)); strcpy(stuRec->last, strtok(NULL, DELIMS)); strcpy(stuRec->first, strtok(NULL, DELIMS)); for(i = 0; i < 6; ++i) stuRec->grades[i] = atoi(strtok(NULL, DELIMS)); stuRec->average = atof(strtok(NULL, DELIMS)); } >How-To-Repeat: just compile the above example with a "gcc filename.c" and do an "./a.out" >Fix: >Release-Note: >Audit-Trail: >Unformatted: