[PATCH] dpkg: create_list: zero terminate list in loop

Bernhard Fischer rep.dot.nop at gmail.com
Thu Jun 5 12:14:57 UTC 2008


On Thu, Jun 05, 2008 at 01:53:17PM +0200, Peter Korsgaard wrote:
>From: Peter Korsgaard <jacmet at sunsite.dk>
>
>Saves a few bytes:
>
>function                                             old     new   delta
>create_list                                          124     103     -21
>------------------------------------------------------------------------------
>(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-21)             Total: -21 bytes
>---
> archival/dpkg.c |    8 ++------
> 1 files changed, 2 insertions(+), 6 deletions(-)
>
>diff --git a/archival/dpkg.c b/archival/dpkg.c
>index 1280ca0..5bc64d5 100644
>--- a/archival/dpkg.c
>+++ b/archival/dpkg.c
>@@ -1164,15 +1164,11 @@ static char **create_list(const char *filename)
> 
> 	while ((line = xmalloc_fgetline(list_stream)) != NULL) {
> 		file_list = xrealloc(file_list, sizeof(char *) * (count + 2));
>-		file_list[count] = line;
>-		count++;
>+		file_list[count++] = line;
>+		file_list[count] = NULL;
> 	}
> 	fclose(list_stream);

Only seeing these lines i wonder if create_list() shouldn't really just be
replaced by xmalloc_xopen_read_close() ?
> 
>-	if (count == 0) {
>-		return NULL;
>-	}
>-	file_list[count] = NULL;
> 	return file_list;
> }



More information about the busybox mailing list