aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
Diffstat (limited to 'libbb')
-rw-r--r--libbb/compare_string_array.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/libbb/compare_string_array.c b/libbb/compare_string_array.c
index 01a9df0e2..a06e57d3d 100644
--- a/libbb/compare_string_array.c
+++ b/libbb/compare_string_array.c
@@ -117,8 +117,11 @@ int FAST_FUNC index_in_substrings(const char *strings, const char *key)
const char* FAST_FUNC nth_string(const char *strings, int n)
{
while (n) {
- n--;
- strings += strlen(strings) + 1;
+ if (*strings++ == '\0') {
+ if (*strings == '\0') /* reached end of strings */
+ break;
+ n--;
+ }
}
return strings;
}