diff options
author | Lucas De Marchi <lucas.demarchi@profusion.mobi> | 2011-12-20 12:04:21 -0200 |
---|---|---|
committer | Lucas De Marchi <lucas.demarchi@profusion.mobi> | 2011-12-20 12:04:21 -0200 |
commit | 76b8031bce288a4052cea5e9fb7cfb7ccde9ca3e (patch) | |
tree | d0a52a02f2210bd51a88fffd42ec0870ad79463d /libkmod/libkmod-elf.c | |
parent | 51c409b449a82283515e7c3fa5a4a0e2f23807fe (diff) | |
download | kmod-76b8031bce288a4052cea5e9fb7cfb7ccde9ca3e.tar.gz |
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.
Diffstat (limited to 'libkmod/libkmod-elf.c')
-rw-r--r-- | libkmod/libkmod-elf.c | 20 |
1 files changed, 15 insertions, 5 deletions
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++; } |