On Tue, Jan 14, 2020 at 04:32:41PM +0100, Alexandr Nedvedicky wrote: > Hello, > > On Tue, Jan 14, 2020 at 03:02:09PM +0100, Klemens Nanni wrote: > > On Mon, Jan 13, 2020 at 10:47:27PM +0100, Alexandr Nedvedicky wrote: > > > @@ -2182,7 +2182,7 @@ pfctl_walk_get(int opts, struct pfioc_ruleset *pr, > > > void *warg) > > > if (pfra == NULL) > > > err(1, "%s", __func__); > > > > > > - len = strlen(pr->path) + 1; > > > + len = (pr->path[0] == '\0') ? 0 : strlen(pr->path) + 1; > > > len += strlen(pr->name) + 1; > > pr->name is always used and only pr->path is optional. With this diff > > you're always adding one with the name altough it is only required if > > path is given (for the "/" delimiter). > > > > len = strlen(pr->name); > > if (pr->path[0]) > > len += strlen(pr->path) + 1; > > > > This reads simpler and clearer to me, what do you think? > > OK, I'll buy if (...) from you, but '+ 1' must stay there, > because it is for a '\0' terminator. So let's go for this: > len = strlen(pr->name) + 1; > if (pr->path[0]) > len += strlen(pr->path) + 1;
I think this should use asprintf() instead.