YMMC yet more malloc checks
Ryan Waldron
rew at erebor.com
Tue Aug 7 20:46:09 GMT 2001
On Tue, 7 Aug 2001, Andreas Moroder wrote:
> in this function even the order is strange, why malloc before the other
> test.
> It should be
>
> static char *
> canonicalize (char *path)
> {
> char *canonical;
>
> if (strlen(path) > PATH_MAX) {
> fprintf(stderr, "Mount point string too long\n");
> return NULL;
> }
>
> if (path == NULL)
> return NULL;
>
> canonical= malloc (PATH_MAX + 1);
> if (canonical==NULL) {
> fprintf(stderr, "Out of memory\n");
> return NULL;
> }
>
> if (realpath (path, canonical))
> return canonical;
>
> pstrcpy (canonical, path);
> return canonical;
> }
Come to think of it, shouldn't that be:
static char *
canonicalize (char *path)
{
char *canonical;
if (path == NULL)
return NULL;
if (strlen(path) > PATH_MAX) {
fprintf(stderr, "Mount point string too long\n");
return NULL;
}
...[etc.]
--
Ryan Waldron ||| http://www.erebor.com ||| rew at erebor.com
"The web goes ever, ever on, down from the site where it began..."
More information about the samba-technical
mailing list