@matheusbsbs / matheus-bagliano / commits / 599b0bf438
Fork 0

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>

Erik Faye-Lund committed Nov 23, 2010 at 19:38 UTC 599b0bf438e387dbaf00dbadcbe41b2a0de90db1
1 file changed +4 -4
compat/msvc.c
+4 -4
@@ -7,16 +7,16 @@ DIR *opendir(const char *name)
7 {
8 int len;
9 DIR *p;
10 - p = (DIR*)malloc(sizeof(DIR));
10 + p = malloc(sizeof(DIR));
11 + if (!p)
12 + return NULL;
13 +
14 memset(p, 0, sizeof(DIR));
15 strncpy(p->dd_name, name, PATH_MAX);
16 len = strlen(p->dd_name);
17 p->dd_name[len] = '/';
18 p->dd_name[len+1] = '*';
19
17 - if (p == NULL)
18 - return NULL;
19 -
20 p->dd_handle = _findfirst(p->dd_name, &p->dd_dta);
21
22 if (p->dd_handle == -1) {