From: Lennart Poettering Date: Thu, 25 Aug 2005 19:36:16 +0000 (+0000) Subject: * fix string list serialization X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=c8207c0a13bfd3365560ed0b3d9dd003f2da63e5;p=catta * fix string list serialization git-svn-id: file:///home/lennart/svn/public/avahi/trunk@447 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- diff --git a/avahi-common/strlst-test.c b/avahi-common/strlst-test.c index b725fa7..abca86d 100644 --- a/avahi-common/strlst-test.c +++ b/avahi-common/strlst-test.c @@ -53,8 +53,10 @@ int main(int argc, char *argv[]) { t = avahi_string_list_to_string(a); printf("--%s--\n", t); avahi_free(t); - + + n = avahi_string_list_serialize(a, NULL, 0); size = avahi_string_list_serialize(a, data, sizeof(data)); + assert(size == n); printf("%u\n", size); @@ -112,8 +114,10 @@ int main(int argc, char *argv[]) { avahi_string_list_free(a); avahi_string_list_free(b); + n = avahi_string_list_serialize(NULL, NULL, 0); size = avahi_string_list_serialize(NULL, data, sizeof(data)); assert(size == 1); + assert(size == n); a = avahi_string_list_parse(data, size); assert(!a); diff --git a/avahi-common/strlst.c b/avahi-common/strlst.c index db5ac59..0c61857 100644 --- a/avahi-common/strlst.c +++ b/avahi-common/strlst.c @@ -200,14 +200,19 @@ size_t avahi_string_list_serialize(AvahiStringList *l, void *data, size_t size) } else { AvahiStringList *n; - for (n = l; n; n = n->next) { - size_t k; - - k = n->size; - if (k > 255) - k = 255; - - used += 1+k; + if (!l) + used = 1; + else { + + for (n = l; n; n = n->next) { + size_t k; + + k = n->size; + if (k > 255) + k = 255; + + used += 1+k; + } } }