GNU bug report logs -
#79194
Segfault with 0 byte symbol
Previous Next
Full log
Message #8 received at 79194 <at> debbugs.gnu.org (full text, mbox):
Hi,
a aa <lgray3420 <at> gmail.com> writes:
> Hello,
>
> how to reproduce:
> cc main.c `pkg-config --libs --cflags guile-3.0` && ./a.out
>
> incorrect behaviour:
> The second parameter for scm_from_utf8_symboln should be how many bytes are
> pointed to by the pointer however the pointer still gets read if the length
> is zero. Being able to handle 0 byte strings is expected since replacing
> the call from scm_from_utf8_symboln to scm_from_utf8_stringn will not have
> a segfault and the documentation for this function does not mention being
> unable to handle 0 byte strings.
Well, the scm_from_utf8_symboln is just not documented at all, so I am
not sure how you have determined that the "documentation for this
function does no mention ...". But let us ignore that for a moment.
You wrote "handle 0 byte *strings*" (emphasis mine). That is not what
you are doing. NULL is not a "0 byte string". "" (almost) is. Or a
char* can be. But not NULL.
>
> [..]
>
> #include <libguile.h>
>
> void* inner_main(void*) {
> SCM sym = scm_from_utf8_symboln(NULL, 0);
The line should be
SCM sym = scm_from_utf8_symboln("", 0);
or
const char zero_str[] = {};
SCM sym = scm_from_utf8_symboln(zero_str, 0);
Both work fine. You cannot just send a null pointer to a function that
is supposed to take a string and expect it to work. So I do not think
it is valid to declare this to be an "incorrect behaviour", maybe
"unexpected" (by you) would be better description.
Tomas
--
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.
This bug report was last modified 8 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.