Skip to content

Commit 599b0bf

Browse files
kusmagitster
authored andcommitted
msvc: opendir: fix malloc-failure
Previsouly, the code checked for malloc-failure after it had accessed the returned pointer. Move the check a bit earlier to avoid segfault. Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 89ba4e7 commit 599b0bf

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

compat/msvc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ DIR *opendir(const char *name)
77
{
88
int len;
99
DIR *p;
10-
p = (DIR*)malloc(sizeof(DIR));
10+
p = malloc(sizeof(DIR));
11+
if (!p)
12+
return NULL;
13+
1114
memset(p, 0, sizeof(DIR));
1215
strncpy(p->dd_name, name, PATH_MAX);
1316
len = strlen(p->dd_name);
1417
p->dd_name[len] = '/';
1518
p->dd_name[len+1] = '*';
1619

17-
if (p == NULL)
18-
return NULL;
19-
2020
p->dd_handle = _findfirst(p->dd_name, &p->dd_dta);
2121

2222
if (p->dd_handle == -1) {

0 commit comments

Comments
 (0)