Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 6 Jul 2005 20:55:36 +0200
From:      Stefan Sperling <stsp@stsp.in-berlin.de>
To:        freebsd-hackers@freebsd.org
Subject:   bus error in strsep
Message-ID:  <20050706185536.GA4700@dice.seeling33.de>

next in thread | raw e-mail | index | archive | help
Hello hackers,

I am getting a bus error in my application when I call strsep
and it matches a character. It doesn't matter whether I call
the strsep from my libc or a freshly compiled one, the error
stays the same.

This is my test case:

$ cat strsep.c

#define NULL ((void*)0)

/* copied verbatim from /usr/src/lib/libc/string/strsep.c,
 * except for the name change
 */
char *
mystrsep(stringp, delim)
	char **stringp;
	const char *delim;
{
	char *s;
	const char *spanp;
	int c, sc;
	char *tok;

	if ((s = *stringp) == NULL)
		return (NULL);
	for (tok = s;;) {
		c = *s++;
		spanp = delim;
		do {
			if ((sc = *spanp++) == c) {
				if (c == 0)
					s = NULL;
				else
					s[-1] = 0;
				*stringp = s;
				return (tok);
			}
		} while (sc != 0);
	}
	/* NOTREACHED */
}

int main(int argc, char* argv[])
{
	char *c = "whats:your:name:buddy?";
	(void*)mystrsep(&c, ":");
}

$ gcc -g -o strsep strsep.c
$ gdb strsep
<gnu license>
(gdb) run
Starting program: /home/stsp/test/strsep

Program received signal SIGBUS, Bus error.
0x080484f2 in mystrsep (stringp=0xbfbfea34, delim=0x80485e6 ":") at strsep.c:26
26                                              s[-1] = 0;
(gdb) print s[-1]
$1 = 58 ':'
(gdb)

When I single step through mystrsep the program works fine.

I am running FreeBSD-current from 17th June 2005 on an Athlon-XP,
no SMP involved. I can reproduce the error on a dual Celeron box
running FreeBSD-5.4-RELEASE with SMP.
And I also get the same error with similar code using strtok.

Can anyone else reproduce this?

thanks a lot,
-- 
stefan
http://stsp.in-berlin.de                                 PGP Key: 0xF59D25F0



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050706185536.GA4700>