summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2002-07-24 19:53:51 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2002-07-24 19:53:51 +0000
commitc8728cedbc3415a2585869d33c442f8264c775aa (patch)
tree36f4fedd3836b2c5838e8bbc96c9825aeafb50d3
parentaf2f5f435eff407bc2aa841173765f4f99ec2719 (diff)
Fix a bug I inadvertanly introduced while fixing the last problem in here.
The item list really did want to be zero-filled since free_items() relies on this to find the end point. However, this is really pretty dumb since we *know* how many items are in the list. This highlights the elusive bug I was trying to fix--free_items() expects the list to be NULL-terminated which was not the case if the list was full. The fix is to simply pass free_items() the number of elements in the list.
-rw-r--r--bin/csh/file.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/bin/csh/file.c b/bin/csh/file.c
index ddb4d17cf12..422b2700fd1 100644
--- a/bin/csh/file.c
+++ b/bin/csh/file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: file.c,v 1.11 2002/07/15 22:10:13 millert Exp $ */
+/* $OpenBSD: file.c,v 1.12 2002/07/24 19:53:50 millert Exp $ */
/* $NetBSD: file.c,v 1.11 1996/11/08 19:34:37 christos Exp $ */
/*-
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)file.c 8.2 (Berkeley) 3/19/94";
#else
-static char rcsid[] = "$OpenBSD: file.c,v 1.11 2002/07/15 22:10:13 millert Exp $";
+static char rcsid[] = "$OpenBSD: file.c,v 1.12 2002/07/24 19:53:50 millert Exp $";
#endif
#endif /* not lint */
@@ -95,7 +95,7 @@ static void beep(void);
static void print_recognized_stuff(Char *);
static void extract_dir_and_name(Char *, Char *, Char *);
static Char *getentry(DIR *, int);
-static void free_items(Char **);
+static void free_items(Char **, int);
static int tsearch(Char *, COMMAND, int);
static int recognize(Char *, Char *, int, int);
static int is_prefix(Char *, Char *);
@@ -412,12 +412,13 @@ getentry(dir_fd, looking_for_lognames)
}
static void
-free_items(items)
- register Char **items;
+free_items(items, numitems)
+ Char **items;
+ int numitems;
{
- register int i;
+ int i;
- for (i = 0; items[i]; i++)
+ for (i = 0; i < numitems; i++)
xfree((ptr_t) items[i]);
xfree((ptr_t) items);
}
@@ -428,7 +429,7 @@ free_items(items)
sigemptyset(&sigset);\
sigaddset(&sigset, SIGINT);\
sigprocmask(SIG_BLOCK, &sigset, &osigset);\
- free_items(items);\
+ free_items(items, numitems);\
sigprocmask(SIG_SETMASK, &osigset, NULL);\
}
@@ -478,10 +479,10 @@ again: /* search for matches */
if (numitems >= maxitems) {
maxitems += 1024;
if (items == NULL)
- items = (Char **) xmalloc(sizeof(items[0]) * maxitems);
+ items = (Char **) xmalloc(sizeof(*items) * maxitems);
else
items = (Char **) xrealloc((ptr_t) items,
- sizeof(items[0]) * maxitems);
+ sizeof(*items) * maxitems);
}
items[numitems] = (Char *) xmalloc((size_t) (Strlen(entry) + 1) *
sizeof(Char));
@@ -523,7 +524,7 @@ again: /* search for matches */
return (numitems);
}
else { /* LIST */
- qsort((ptr_t) items, numitems, sizeof(items[0]),
+ qsort((ptr_t) items, numitems, sizeof(*items),
(int (*)(const void *, const void *)) sortscmp);
print_by_column(looking_for_lognames ? NULL : tilded_dir,
items, numitems);