src/nnn.c | 13 ++++++++++--- diff --git a/src/nnn.c b/src/nnn.c index 5c6027815912757adbfc9edf388c68a91629c073..1b9f7a2b867bc7c620248601592c6fa91f7999e0 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -6134,6 +6134,7 @@ /* 512 KiB chunk size */ ssize_t i, chunk_count = 1, chunk = 512 * 1024, entries = 0; char *input = malloc(sizeof(char) * chunk), *tmpdir = NULL; char cwd[PATH_MAX], *next, *tmp; + size_t offsets[1 << 16]; char *paths[1 << 16]; ssize_t input_read, total_read = 0, off = 0; @@ -6170,28 +6171,34 @@ if (entries == (1 << 16)) goto malloc_1; - paths[entries++] = input + off; + offsets[entries++] = off; off = next - input; } if (input_read < chunk) break; - if (chunk_count == 512 || !(input = xrealloc(input, (chunk_count + 1) * chunk))) + if (chunk_count == 512) goto malloc_1; + + if (!(input = xrealloc(input, (chunk_count + 1) * chunk))) + return NULL; } if (off != total_read) { if (entries == (1 << 16)) goto malloc_1; - paths[entries++] = input + off; + offsets[entries++] = off; } if (!entries) goto malloc_1; input[total_read] = '\0'; + + for (i = 0; i < entries; ++i) + paths[i] = input + offsets[i]; g_prefixpath = malloc(sizeof(char) * PATH_MAX); if (!g_prefixpath)