projects
/
mono.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
[sgen] Use array with fixed-size element for mark words
[mono.git]
/
support
/
x-struct-str.c
diff --git
a/support/x-struct-str.c
b/support/x-struct-str.c
index 89d5a61b120b6227f36aaad323efd33810fcf631..5124af71fc948720d20fb6be1a350e0974615bc2 100644
(file)
--- a/
support/x-struct-str.c
+++ b/
support/x-struct-str.c
@@
-20,7
+20,7
@@
: lstr_at(p, n) \
)
: 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,
_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) {
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
if (len[i] < INT_MAX - buflen)
buflen += len[i];
else
@@
-64,6
+65,12
@@
_mph_copy_structure_strings (
#ifdef TEST
#ifdef TEST
+/*
+ * To run the tests:
+ * $ gcc -DTEST -I.. `pkg-config --cflags --libs glib-2.0` x-struct-str.c
+ * $ ./a.out
+ */
+
#include <stdio.h>
struct foo {
#include <stdio.h>
struct foo {
@@
-105,6
+112,13
@@
main ()
printf ("b.c=%s\n", b.c);
printf ("b.e=%s\n", b.e);
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
return 0;
}
#endif