From nobody Fri Jan 03 15:48:59 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4YPp0C5dRHz5k75V; Fri, 03 Jan 2025 15:48:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YPp0C4W5Bz4WbG; Fri, 3 Jan 2025 15:48:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1735919339; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=NccObzWe2SnBR2kB8W1UU/3308/9eZ4HKteabJRrTqQ=; b=pdOHuIaRTSMg5G2cUw7z7TlEO7/c7t1MfrUkzYbmkH2YZZFKpV8jfscqO8sgRVTcP+38Br 95j3Oxy4qu9y7Ua2AUGM4/HjA9sNrpXv+queCKuOAqsHvwcMs45t+8IqbXZ7OaNI+fJaFL EANJHF6kC+wbxVi6YLHw0nfO6sxrecVuxzXVyQleltzsAo8PDsWXDqLGLus5Qte/jhdc8H 0gCMGVL2ASuAeWLekicrHSFXoaC8L4WrMgF/1xGCH0DyLz2IBCOTd03MRjnD9x6FbL0btY zvxBuIaGaFvhTjFj+GgkNBltuMgBF8s2yax48S8g9HuMS/RCDj4bm8cYnfM3Ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1735919339; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=NccObzWe2SnBR2kB8W1UU/3308/9eZ4HKteabJRrTqQ=; b=FVjDWv9lSiMqokmbPSkr+mF3UpVBJ5Wy/4v+ld3+IN/oREVIROnfVFyO+BJII7DKQmEC/m 60PnSsubVS69UBb+6P2bWQRGARu7EBhmRL5w3OnDu9p7voSQ/lsGc/PNfNCzfIiRTVmTON uymNR7unN/2CVf/SxY6AtRKrb51WaT/1MOq9TDGBcXKm7E+pT+wIbMI26nhNc7jDTl6yE9 jVFcp6B9AfHcq0+lskM00OtlrrxEUOlCFuTkDglnKvIYy+GZrTglprLEQ7/WgmkLoaTdrt RCCFxOOaAbB2asegm0ukZIbB86NC/zThziQt0Qwdk9EEgChuz2vsWsyPjqICFw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1735919339; a=rsa-sha256; cv=none; b=DRcQpSzy9rOtawLfeDSejJKrXo1TK6ApP0LnqgMk5Wf3BIdyGJvr3ecqzBeF4ZiBWt6YqZ GjQowHRlX7/HTOukIStwWEV2I5JThWWxALQKel3jH3s+R/9+5rI3gTZL71ARRnyYCS0LIb iToCUq9nC3i0qH1VrBHX583eiQAo01Cl0WuUtCD58DqjD8XGDSGkXZYlKh09j2E6tnVY2N cSDxOm7eqWGjsHqlkulhALO47qhc3HTEY2UsJAlttimn9dv00U5zZE/I7hfIaU89KdJ47l g6txu22gRaw09e3skIF7v+Lu73QKjJjwR9zT18bLQSlzVDvUSgyGIFYkagL4BA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4YPp0C3j8Nz1RXs; Fri, 03 Jan 2025 15:48:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 503FmxbY060531; Fri, 3 Jan 2025 15:48:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 503Fmxei060528; Fri, 3 Jan 2025 15:48:59 GMT (envelope-from git) Date: Fri, 3 Jan 2025 15:48:59 GMT Message-Id: <202501031548.503Fmxei060528@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: f94513a3a36b - main - pac: Use strdup and asprintf in place of dubious string building List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f94513a3a36b50823c3918c93ee5c6bf5f525e91 Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=f94513a3a36b50823c3918c93ee5c6bf5f525e91 commit f94513a3a36b50823c3918c93ee5c6bf5f525e91 Author: John Baldwin AuthorDate: 2025-01-03 15:39:44 +0000 Commit: John Baldwin CommitDate: 2025-01-03 15:44:22 +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. --- 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 1cc0e050a99e..22ed8bf7e3bb 100644 --- a/usr.sbin/lpr/pac/pac.c +++ b/usr.sbin/lpr/pac/pac.c @@ -327,8 +327,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]; @@ -429,10 +428,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); }