Date: Thu, 13 Feb 2025 17:51:29 GMT From: John Baldwin <jhb@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: ac2170b99551 - stable/14 - pac: Use strdup and asprintf in place of dubious string building Message-ID: <202502131751.51DHpTDp069185@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=ac2170b9955134c66f0e820b9dc1daa8f4d0e6a3 commit ac2170b9955134c66f0e820b9dc1daa8f4d0e6a3 Author: John Baldwin <jhb@FreeBSD.org> AuthorDate: 2025-01-03 15:39:44 +0000 Commit: John Baldwin <jhb@FreeBSD.org> CommitDate: 2025-02-13 16:01:19 +0000 pac: Use strdup and asprintf in place of dubious string building GCC 14 warned about transposed arguments to calloc, but these cases are better served by more abstract string functions. (cherry picked from commit f94513a3a36b50823c3918c93ee5c6bf5f525e91) --- usr.sbin/lpr/pac/pac.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/usr.sbin/lpr/pac/pac.c b/usr.sbin/lpr/pac/pac.c index 85c9327f433f..5eb5cab02353 100644 --- a/usr.sbin/lpr/pac/pac.c +++ b/usr.sbin/lpr/pac/pac.c @@ -339,8 +339,7 @@ enter(const char name[]) h = hash(name); hcount++; hp = (struct hent *) calloc(sizeof *hp, (size_t)1); - hp->h_name = (char *) calloc(sizeof(char), strlen(name)+1); - strcpy(hp->h_name, name); + hp->h_name = strdup(name); hp->h_feetpages = 0.0; hp->h_count = 0; hp->h_link = hashtab[h]; @@ -441,10 +440,8 @@ chkprinter(const char *ptrname) errx(3, "accounting not enabled for printer %s", ptrname); if (!pflag && pp->price100) price = pp->price100/10000.0; - sumfile = (char *) calloc(sizeof(char), strlen(acctfile)+5); + asprintf(&sumfile, "%s_sum", acctfile); if (sumfile == NULL) - errx(1, "calloc failed"); - strcpy(sumfile, acctfile); - strcat(sumfile, "_sum"); + errx(1, "asprintf failed"); return(1); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202502131751.51DHpTDp069185>