aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2025-01-03 15:39:44 +0000
committerJohn Baldwin <jhb@FreeBSD.org>2025-02-13 17:49:02 +0000
commit74a5a7d842367f239c7d6f628c3a97f9a467ed84 (patch)
tree9f770a7bc53907df1a4ab926beb7a6b1abe12778
parentdcd7286d902774428c08b179a72bfdcd4556ec06 (diff)
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)
-rw-r--r--usr.sbin/lpr/pac/pac.c9
1 files 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);
}