From 1b14e601434435f48dfe1027a117c2af3dac325b Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sun, 21 Jun 2020 18:08:41 +0200 Subject: sfeed_html/sfeed_frames: simplify struct feed allocation There's no need for a dynamic struct feed **. The required size is known (argc). Just allocate it in one go. --- sfeed_frames.c | 18 +++++++----------- sfeed_html.c | 18 +++++++----------- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/sfeed_frames.c b/sfeed_frames.c index dd50de1..972f9ce 100644 --- a/sfeed_frames.c +++ b/sfeed_frames.c @@ -8,7 +8,7 @@ #include "util.h" -static struct feed **feeds; +static struct feed *feeds; static char *line; static size_t linesize; static time_t comparetime; @@ -82,7 +82,7 @@ main(int argc, char *argv[]) if (pledge("stdio rpath wpath cpath", NULL) == -1) err(1, "pledge"); - if (!(feeds = calloc(argc, sizeof(struct feed *)))) + if (!(feeds = calloc(argc, sizeof(struct feed)))) err(1, "calloc"); if ((comparetime = time(NULL)) == -1) @@ -111,20 +111,16 @@ main(int argc, char *argv[]) "
", fpitems); if (argc == 1) { - if (!(feeds[0] = calloc(1, sizeof(struct feed)))) - err(1, "calloc"); - feeds[0]->name = ""; - printfeed(fpitems, stdin, feeds[0]); + feeds[0].name = ""; + printfeed(fpitems, stdin, &feeds[0]); } else { for (i = 1; i < argc; i++) { - if (!(feeds[i - 1] = calloc(1, sizeof(struct feed)))) - err(1, "calloc"); name = ((name = strrchr(argv[i], '/'))) ? name + 1 : argv[i]; - feeds[i - 1]->name = name; + feeds[i - 1].name = name; if (!(fp = fopen(argv[i], "r"))) err(1, "fopen: %s", argv[i]); - printfeed(fpitems, fp, feeds[i - 1]); + printfeed(fpitems, fp, &feeds[i - 1]); if (ferror(fp)) err(1, "ferror: %s", argv[i]); fclose(fp); @@ -142,7 +138,7 @@ main(int argc, char *argv[]) "\n