Re: g_strchug/g_strchomp/g_strstrip crash



On Fri, Sep 08, 2000 at 05:50:42PM -0400, Joe Shaw wrote:
> If a string passed to the g_strchug/g_strchomp/g_strstrip functions
> consists of all spaces, it crashes.

I don't see why "g_strchug()" would crash; when handed an all-space
string, it would stop at the terminating '\0' and then move that '\0'
down to the beginning of the string ("start" would point to the '\0',
and the length argument to "g_memmove()" would be 1, so it moves the
'\0' to the beginning of the string).

I also don't see why "g_strchomp()" would crash; when handed an
all-space string, it would start at the last space, and skip backwards,
replacing each space with '\0', until "s" pointed just before the
beginning of the string, and would then return the all-nulled-out
string.

And "g_strstrip()" just runs "g_strchug()" and then "g_strchomp()" on
the string; the former would return a null string, causing
"g_strchomp()" to return a pointer to that string.

None of them crashed, at least on my x86/FreeBSD box, with Glib 1.2.8,
when I ran the following test program:

	#include <stdio.h>
	#include <glib.h>

	int
	main(int argc, char **argv)
	{
		char buf1[] = "      ";
		char buf2[] = "      ";
		char buf3[] = "      ";

		printf("%s\n", g_strchug(buf1));
		printf("%s\n", g_strchomp(buf2));
		printf("%s\n", g_strstrip(buf3));
		return 0;
	}

What am I missing?




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]