summaryrefslogtreecommitdiff
path: root/sfeed_curses.c
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2022-01-13 23:59:21 +0100
committerHiltjo Posthuma <hiltjo@codemadness.org>2022-01-14 00:03:38 +0100
commit20686256dbc94fd693607abd5165ecc9901dd1e3 (patch)
tree31de065ef623dca1af4545f6e6298acab866a49f /sfeed_curses.c
parent790a941eb0c78867f744d0551ac20b421b6c75e2 (diff)
sfeed_curses: pedantic fix for UB with an empty URL file
When a new URL file is used with no URL entries then NULL is passed to qsort() and bsearch(). This is reported by clang UBsan as undefined behaviour (debatable), but no issue in practise with many implementations. Fix it anyway. To reproduce with clang UBsan: Compile with clang or gcc with CFLAGS and LDFLAGS -fsanitize=undefined touch /tmp/urls # new file which should be empty. SFEED_URL_FILE=/tmp/urls sfeed_curses 2>/tmp/log ^D q cat /tmp/log
Diffstat (limited to 'sfeed_curses.c')
-rw-r--r--sfeed_curses.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/sfeed_curses.c b/sfeed_curses.c
index d4ca13d..6adbfec 100644
--- a/sfeed_curses.c
+++ b/sfeed_curses.c
@@ -1886,7 +1886,8 @@ urls_cmp(const void *v1, const void *v2)
int
urls_isnew(const char *url)
{
- return bsearch(&url, urls, nurls, sizeof(char *), urls_cmp) == NULL;
+ return (!nurls ||
+ bsearch(&url, urls, nurls, sizeof(char *), urls_cmp) == NULL);
}
void
@@ -1928,7 +1929,8 @@ urls_read(void)
fclose(fp);
free(line);
- qsort(urls, nurls, sizeof(char *), urls_cmp);
+ if (nurls > 0)
+ qsort(urls, nurls, sizeof(char *), urls_cmp);
}
int