Skip to contentSkip to conversation

test-string-output-visitor: Fix unterminated string

PATCH In review Kevin Wolf 2 participants 3 messages Jul 9, 2014 – Jul 10, 2014

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

PATCH 1/1 test-string-output-visitor: Fix unterminated string

Don't forget to add a terminating '\0' or the test case will be randomly failing. The broken code was added in commit b4900c0e.

---
 tests/test-string-output-visitor.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tests/test-string-output-visitor.c +2 -2
index e89e43c..f2c427f 100644
@@ -201,11 +201,11 @@ static void test_visitor_out_enum(TestOutputVisitorData *data,
         visit_type_EnumOne(data->ov, &i, "unused", &err);
         g_assert(!err);
 
-        len = strlen(EnumOne_lookup[i]) + 2;
+        len = strlen(EnumOne_lookup[i]) + 3;
         str_human = g_malloc0(len);
         str_human[0] = '"';
         strncpy(str_human + 1, EnumOne_lookup[i], strlen(EnumOne_lookup[i]));
-        str_human[len - 1] = '"';
+        str_human[len - 2] = '"';
 
         str = string_output_get_string(data->sov);
         g_assert(str != NULL);
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 2 lines · Kevin Wolf

Don't forget to add a terminating '\0' or the test case will be randomly failing. The broken code was added in commit b4900c0e.

Sorry, but I prefer this solution better:
https://lists.gnu.org/archive/html/qemu-devel/2014-07/msg01595.html

Quoted 11 lines
---
 tests/test-string-output-visitor.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tests/test-string-output-visitor.c +0 -0
index e89e43c..f2c427f 100644

tests/test-string-output-visitor.c static void test_visitor_out_enum(TestOutputVisitorData *data, · line 208

Quoted 10 lines
tests/test-string-output-visitor.c +2 -2
@@ -201,11 +201,11 @@ static void test_visitor_out_enum(TestOutputVisitorData *data,
         visit_type_EnumOne(data->ov, &i, "unused", &err);
         g_assert(!err);
 
-        len = strlen(EnumOne_lookup[i]) + 2;
+        len = strlen(EnumOne_lookup[i]) + 3;
         str_human = g_malloc0(len);
         str_human[0] = '"';
         strncpy(str_human + 1, EnumOne_lookup[i], strlen(EnumOne_lookup[i]));
-        str_human[len - 1] = '"';
+        str_human[len - 2] = '"';

Manually doing this when g_strdup_printf can do it as a one-liner is just lunacy.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
author
#2 lore raw

Am 10.07.2014 um 03:41 hat Eric Blake geschrieben:

Quoted 6 lines · Kevin Wolf
Quoted 2 lines

Don't forget to add a terminating '\0' or the test case will be randomly failing. The broken code was added in commit b4900c0e.

Sorry, but I prefer this solution better:
https://lists.gnu.org/archive/html/qemu-devel/2014-07/msg01595.html

Fine with me, as long as my 'make check' gets fixed. :-)

Kevin