The branch stable/14 has been updated by jhb:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=ac2170b9955134c66f0e820b9dc1daa8f4d0e6a3

commit ac2170b9955134c66f0e820b9dc1daa8f4d0e6a3
Author:     John Baldwin <j...@freebsd.org>
AuthorDate: 2025-01-03 15:39:44 +0000
Commit:     John Baldwin <j...@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);
 }

Reply via email to