Преглед изворни кода

xrealloc() may move memory

master
Arun Prakash Jana пре 5 година
родитељ
комит
6faab79ba9
No known key found for this signature in database GPG Key ID: A75979F35C080412
1 измењених фајлова са 10 додато и 3 уклоњено
  1. +10
    -3
      src/nnn.c

+ 10
- 3
src/nnn.c Прегледај датотеку

@@ -6134,6 +6134,7 @@ static char *load_input()
ssize_t i, chunk_count = 1, chunk = 512 * 1024, entries = 0; ssize_t i, chunk_count = 1, chunk = 512 * 1024, entries = 0;
char *input = malloc(sizeof(char) * chunk), *tmpdir = NULL; char *input = malloc(sizeof(char) * chunk), *tmpdir = NULL;
char cwd[PATH_MAX], *next, *tmp; char cwd[PATH_MAX], *next, *tmp;
size_t offsets[1 << 16];
char *paths[1 << 16]; char *paths[1 << 16];
ssize_t input_read, total_read = 0, off = 0; ssize_t input_read, total_read = 0, off = 0;


@@ -6170,22 +6171,25 @@ static char *load_input()
if (entries == (1 << 16)) if (entries == (1 << 16))
goto malloc_1; goto malloc_1;


paths[entries++] = input + off; offsets[entries++] = off;
off = next - input; off = next - input;
} }


if (input_read < chunk) if (input_read < chunk)
break; break;


if (chunk_count == 512 || !(input = xrealloc(input, (chunk_count + 1) * chunk))) if (chunk_count == 512)
goto malloc_1; goto malloc_1;

if (!(input = xrealloc(input, (chunk_count + 1) * chunk)))
return NULL;
} }


if (off != total_read) { if (off != total_read) {
if (entries == (1 << 16)) if (entries == (1 << 16))
goto malloc_1; goto malloc_1;


paths[entries++] = input + off; offsets[entries++] = off;
} }


if (!entries) if (!entries)
@@ -6193,6 +6197,9 @@ static char *load_input()


input[total_read] = '\0'; input[total_read] = '\0';


for (i = 0; i < entries; ++i)
paths[i] = input + offsets[i];

g_prefixpath = malloc(sizeof(char) * PATH_MAX); g_prefixpath = malloc(sizeof(char) * PATH_MAX);
if (!g_prefixpath) if (!g_prefixpath)
goto malloc_1; goto malloc_1;


||||||
x
 
000:0
Loading…
Откажи
Сачувај