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.
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++;
}
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++;
}