public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: ocmbah@unity.ncsu.edu To: gcc-gnats@gcc.gnu.org Subject: c/9857: string tokenizer causes segmentation faults Date: Wed, 26 Feb 2003 05:46:00 -0000 [thread overview] Message-ID: <20030226054351.17181.qmail@sources.redhat.com> (raw) >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 <stdio.h> #include <string.h> #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:
next reply other threads:[~2003-02-26 5:46 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2003-02-26 5:46 ocmbah [this message] 2003-02-26 13:23 steven
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20030226054351.17181.qmail@sources.redhat.com \ --to=ocmbah@unity.ncsu.edu \ --cc=gcc-gnats@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).