From: Junio C Hamano Date: Fri, 26 Nov 2010 18:34:48 GMT Subject: Re: [PATCH v2 2/6] msvc: opendir: allocate enough memory Message-ID: <7vfwuoq6gn.fsf@alter.siamese.dyndns.org> In-Reply-To: <1290537509-360-3-git-send-email-kusmabite@gmail.com> Erik Faye-Lund writes: > 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); I'd queue this anyway, but I think you do not have to memset() that many bytes. It should be enough to clear sizeof(DIR) here; you have to assign NUL p->dd_name[len+2] though. > p->dd_name[len] = '/'; > p->dd_name[len+1] = '*'; > > -- > 1.7.3.2.493.gc8738