- Don't update the size of allocated storage until realloc successes.

- KNF left over.
This commit is contained in:
enami 2000-01-25 16:24:40 +00:00
parent 0cd03c86b4
commit 6e75e4cb47
1 changed files with 6 additions and 5 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: stringlist.c,v 1.9 2000/01/22 22:19:12 mycroft Exp $ */
/* $NetBSD: stringlist.c,v 1.10 2000/01/25 16:24:40 enami Exp $ */
/*-
* Copyright (c) 1994, 1999 The NetBSD Foundation, Inc.
@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: stringlist.c,v 1.9 2000/01/22 22:19:12 mycroft Exp $");
__RCSID("$NetBSD: stringlist.c,v 1.10 2000/01/25 16:24:40 enami Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
@ -96,10 +96,11 @@ sl_add(sl, name)
if (sl->sl_cur == sl->sl_max - 1) {
char **new;
sl->sl_max += _SL_CHUNKSIZE;
new = (char **)realloc(sl->sl_str, sl->sl_max * sizeof(char *));
new = (char **)realloc(sl->sl_str,
(sl->sl_max + _SL_CHUNKSIZE) * sizeof(char *));
if (new == NULL)
return (-1);
sl->sl_max += _SL_CHUNKSIZE;
sl->sl_str = new;
}
sl->sl_str[sl->sl_cur++] = name;
@ -146,7 +147,7 @@ sl_find(sl, name)
* XXX check sl->sl_str[i] != NULL?
*/
if (strcmp(sl->sl_str[i], name) == 0)
return sl->sl_str[i];
return (sl->sl_str[i]);
return (NULL);
}