Re: [PATCH v2 2/6] msvc: opendir: allocate enough memory
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Nov 26, 2010, 18:34 UTC
- Message-ID
- <7vfwuoq6gn.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <1290537509-360-3-git-send-email-kusmabite@gmail.com>
Erik Faye-Lund <kusmabite@gmail.com> writes:
Show 15 quoted lines
> 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.
Show 5 quoted lines
> p->dd_name[len] = '/'; > p->dd_name[len+1] = '*'; > > -- > 1.7.3.2.493.gc8738