elf: fix regression with empty strings
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Tue, 20 Dec 2011 14:04:21 +0000 (12:04 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Tue, 20 Dec 2011 14:04:21 +0000 (12:04 -0200)
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.

libkmod/libkmod-elf.c

index 70bbb2c..0eb22b8 100644 (file)
@@ -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++;
        }