From: Erik Faye-Lund Date: Tue, 23 Nov 2010 18:38:25 +0000 (+0100) Subject: msvc: opendir: allocate enough memory X-Git-Tag: v1.7.4-rc0~58^2~4 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/17194c1e96eddb43d2608fe7bd121256d17118ee msvc: opendir: allocate enough memory The defintion of DIR expects the allocating function to extend dd_name by over-allocating. This is not currently done in our implementation of opendir. Fix this. Signed-off-by: Erik Faye-Lund Signed-off-by: Junio C Hamano --- diff --git a/compat/msvc.c b/compat/msvc.c index d6096e4bd9..c195365d2c 100644 --- a/compat/msvc.c +++ b/compat/msvc.c @@ -5,15 +5,14 @@ DIR *opendir(const char *name) { - int len; + int len = strlen(name); DIR *p; - p = malloc(sizeof(DIR)); + p = malloc(sizeof(DIR) + len + 2); if (!p) return NULL; - memset(p, 0, sizeof(DIR)); - strncpy(p->dd_name, name, PATH_MAX); - len = strlen(p->dd_name); + memset(p, 0, sizeof(DIR) + len + 2); + strcpy(p->dd_name, name); p->dd_name[len] = '/'; p->dd_name[len+1] = '*';