Page MenuHomePhabricator

eina strbuf_substr_get test is borked
Closed, ResolvedPublic

Description

Hi,

Eina's test suite fails on me. I wonder if it's been tested somehow ?

eina_strbuf_append(buf, "string");
substr = eina_strbuf_substr_get(buf, 2, 3);
str = eina_strbuf_string_get(substr);
fail_unless(str || strcmp(str, "rin"));
eina_strbuf_free(substr);

How could that `fail_unless' (and the other ones) possibly work as intended ? Beside the mistake in the indexes, shouldn't it be a '&&' intended to be used there, instead ?

Anyway, here's what i get

Program received signal SIGSEGV, Segmentation fault.
eina_strbuf_common_string_get (buf=buf@entry=0x0) at lib/eina/eina_strbuf_common.c:716
716	   return buf->buf;
(gdb) bt
#0  eina_strbuf_common_string_get (buf=buf@entry=0x0) at lib/eina/eina_strbuf_common.c:716
#1  0x00007ffff7070c75 in eina_strbuf_string_get (buf=buf@entry=0x0) at lib/eina/eina_binbuf_template_c.x:151
#2  0x000000000042dcea in strbuf_substr_get (_i=<optimized out>) at tests/eina/eina_test_strbuf.c:543
#3  0x000000000046042b in tcase_run_tfun_nofork.isra ()
#4  0x000000000046081d in srunner_run ()
#5  0x000000000040ddd6 in main (argc=<optimized out>, argv=0x7fffffffeae8) at tests/eina/eina_suite.c:201
(gdb) up
#1  0x00007ffff7070c75 in eina_strbuf_string_get (buf=buf@entry=0x0) at lib/eina/eina_binbuf_template_c.x:151
151	   return (const _STRBUF_DATA_TYPE *) eina_strbuf_common_string_get(buf);
(gdb) up
#2  0x000000000042dcea in strbuf_substr_get (_i=<optimized out>) at tests/eina/eina_test_strbuf.c:543
543	   str = eina_strbuf_string_get(substr);
(gdb) list
538	   str = eina_strbuf_string_get(substr);
539	   fail_unless(str || strcmp(str, "0"));
540	   eina_strbuf_free(substr);
541
542	   substr = eina_strbuf_substr_get(buf, 6, 1);
543	   str = eina_strbuf_string_get(substr);
544	   fail_if(str);
545	   eina_strbuf_free(substr);
546
547	   substr = eina_strbuf_substr_get(buf, 0, 7);

I'd have liked to help to write a patch, but I'm affraid the API documentation of eina_strbuf_string_get doesn't specify what should its behaviour be in presence of a null argument. So maybe it would be useful to fix that as well ?

Thanks