public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c/9857: string tokenizer causes segmentation faults
@ 2003-02-26 13:23 steven
  0 siblings, 0 replies; 2+ messages in thread
From: steven @ 2003-02-26 13:23 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, ocmbah

Synopsis: string tokenizer causes segmentation faults

State-Changed-From-To: open->closed
State-Changed-By: steven
State-Changed-When: Wed Feb 26 13:23:02 2003
State-Changed-Why:
    This is not a compiler bug.  You can't use strtok on constant strings.  See the manpages. (Note that those also say: "Never use these functions.")

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=9857


^ permalink raw reply	[flat|nested] 2+ messages in thread

* c/9857: string tokenizer causes segmentation faults
@ 2003-02-26  5:46 ocmbah
  0 siblings, 0 replies; 2+ messages in thread
From: ocmbah @ 2003-02-26  5:46 UTC (permalink / raw)
  To: gcc-gnats


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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-02-26 13:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-26 13:23 c/9857: string tokenizer causes segmentation faults steven
  -- strict thread matches above, loose matches on Subject: below --
2003-02-26  5:46 ocmbah

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