X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=support%2Fx-struct-str.c;h=5124af71fc948720d20fb6be1a350e0974615bc2;hb=b0f00d71a9cb02b2ce015b40733adb7e3a76a113;hp=89d5a61b120b6227f36aaad323efd33810fcf631;hpb=9d94ef745654af93546b585ab66b3f2638defdcb;p=mono.git diff --git a/support/x-struct-str.c b/support/x-struct-str.c index 89d5a61b120..5124af71fc9 100644 --- a/support/x-struct-str.c +++ b/support/x-struct-str.c @@ -20,7 +20,7 @@ : lstr_at(p, n) \ ) -char* MPH_INTERNAL +char* _mph_copy_structure_strings ( void *to, const mph_string_offset_t *to_offsets, const void *from, const mph_string_offset_t *from_offsets, @@ -39,7 +39,8 @@ _mph_copy_structure_strings ( buflen = num_strings; for (i = 0; i < num_strings; ++i) { - len[i] = strlen (str_at(from, from_offsets[i])); + const char* s = str_at(from, from_offsets[i]); + len [i] = s ? strlen (s) : 0; if (len[i] < INT_MAX - buflen) buflen += len[i]; else @@ -64,6 +65,12 @@ _mph_copy_structure_strings ( #ifdef TEST +/* + * To run the tests: + * $ gcc -DTEST -I.. `pkg-config --cflags --libs glib-2.0` x-struct-str.c + * $ ./a.out + */ + #include struct foo { @@ -105,6 +112,13 @@ main () printf ("b.c=%s\n", b.c); printf ("b.e=%s\n", b.e); + f.c = NULL; + buf = _mph_copy_structure_strings (&b, bar_offsets, + &f, foo_offsets, 3); + printf ("b.a=%s\n", b.a); + printf ("b.c=%s\n", b.c); + printf ("b.e=%s\n", b.e); + return 0; } #endif