From: Lucas De Marchi Date: Tue, 20 Dec 2011 14:04:21 +0000 (-0200) Subject: elf: fix regression with empty strings X-Git-Tag: v2~21 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=76b8031bce288a4052cea5e9fb7cfb7ccde9ca3e;p=platform%2Fupstream%2Fkmod.git elf: fix regression with empty strings Commit "b20dc17 Remove unneeded reference to last string" reverted the fix in "47a0ef6 elf: do not output empty strings." and empty strings are appearing again in kmod-modinfo. With this commit we do a bit different and instead of keeping the reference to last string we skip the '\0' inside the loop. --- diff --git a/libkmod/libkmod-elf.c b/libkmod/libkmod-elf.c index 70bbb2c..0eb22b8 100644 --- a/libkmod/libkmod-elf.c +++ b/libkmod/libkmod-elf.c @@ -420,9 +420,14 @@ int kmod_elf_get_strings(const struct kmod_elf *elf, const char *section, char * if (size <= 1) return 0; - for (i = 0, count = 0; i < size; i++) { - if (strings[i] != '\0') + for (i = 0, count = 0; i < size; ) { + if (strings[i] != '\0') { + i++; continue; + } + + while (strings[i] == '\0' && i < size) + i++; count++; } @@ -442,11 +447,16 @@ int kmod_elf_get_strings(const struct kmod_elf *elf, const char *section, char * a[count] = NULL; a[0] = s; - for (i = 0, j = 1; j < count && i < size; i++) { - if (s[i] != '\0') + for (i = 0, j = 1; j < count && i < size; ) { + if (s[i] != '\0') { + i++; continue; + } + + while (strings[i] == '\0' && i < size) + i++; - a[j] = &s[i + 1]; + a[j] = &s[i]; j++; }