From 2dfff6604492b72f3dd990571e2925a8cea746f5 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Thu, 20 Apr 2023 16:01:52 -0400 Subject: opk: Fix column width calculation Also fix possibly uninitialized list tail. --- (limited to 'src') diff --git a/src/opk.c b/src/opk.c index ddcacea..015ad96 100644 --- a/src/opk.c +++ b/src/opk.c @@ -251,6 +251,7 @@ opkg_opk_opk_list_members(struct opkg_opk_opk *opk) /* Build singly-linked list and find maximum column widths. */ head = NULL; + tail = NULL; uname_len_max = 0; gname_len_max = 0; size_max = 0; @@ -279,14 +280,16 @@ opkg_opk_opk_list_members(struct opkg_opk_opk *opk) _opkg_opk_opk_free_inner(opk); return OPKG_OPK_ERROR; } - tail->next = NULL; + if (tail != NULL) { + tail->next = NULL; + } /* Print and free members. */ ret = OPKG_OPK_OK; size_len_max = lrint(ceil(log10(size_max))); snprintf(fmt, sizeof(fmt), "%%c%%s %%-%zus/%%-%zus %%%lid %%s %%s\n", - uname_len, gname_len, size_len_max); - len = 35 + uname_len + gname_len + size_len_max; + uname_len_max, gname_len_max, size_len_max); + len = 35 + uname_len_max + gname_len_max + size_len_max; for (member = head; member != NULL;) { if (member->mode & 00400) mode[0] = 'r'; else mode[0] = '-'; if (member->mode & 00200) mode[1] = 'w'; else mode[1] = '-'; -- cgit v0.9.1