Hello </snip> > > > > > > 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. >
and you are right. thanks and regards sashan --------8<---------------8<---------------8<------------------8<-------- diff --git a/sbin/pfctl/pfctl.c b/sbin/pfctl/pfctl.c index 9c5778f4f97..16251d2e289 100644 --- a/sbin/pfctl/pfctl.c +++ b/sbin/pfctl/pfctl.c @@ -2173,7 +2173,6 @@ int pfctl_walk_get(int opts, struct pfioc_ruleset *pr, void *warg) { struct pfr_anchoritem *pfra; - size_t len; struct pfr_anchors *anchors; anchors = (struct pfr_anchors *) warg; @@ -2182,19 +2181,15 @@ pfctl_walk_get(int opts, struct pfioc_ruleset *pr, void *warg) if (pfra == NULL) err(1, "%s", __func__); - len = strlen(pr->name) + 1; + pfra->pfra_anchorname = NULL; if (pr->path[0]) - len += strlen(pr->path) + 1; + asprintf(&pfra->pfra_anchorname, "%s/%s", pr->path, pr->name); + else + asprintf(&pfra->pfra_anchorname, "%s", pr->name); - pfra->pfra_anchorname = malloc(len); if (pfra->pfra_anchorname == NULL) err(1, "%s", __func__); - if (pr->path[0]) - snprintf(pfra->pfra_anchorname, len, "%s/%s", - pr->path, pr->name); - else - snprintf(pfra->pfra_anchorname, len, "%s", pr->name); SLIST_INSERT_HEAD(anchors, pfra, pfra_sle);