git: 74a5a7d84236 - stable/13 - pac: Use strdup and asprintf in place of dubious string building
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 13 Feb 2025 17:51:35 UTC
The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=74a5a7d842367f239c7d6f628c3a97f9a467ed84 commit 74a5a7d842367f239c7d6f628c3a97f9a467ed84 Author: John Baldwin <jhb@FreeBSD.org> AuthorDate: 2025-01-03 15:39:44 +0000 Commit: John Baldwin <jhb@FreeBSD.org> CommitDate: 2025-02-13 17:49:02 +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); }