From nobody Thu Oct 13 08:36:48 2022 X-Original-To: dev-commits-src-all@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 4Mp2tm4r9vz4fRMr; Thu, 13 Oct 2022 08:36:48 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Mp2tm43YHz3tBj; Thu, 13 Oct 2022 08:36:48 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1665650208; 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=MjaVDcGzt6/x4asyBVNFiobzQ1eXo1eFwyNBPfsGWSU=; b=WEMOtuYoFHXW83gWl+/PahukiGK+eFvXvSZx6L76ju4OoxmvtCHh6GkQdC/JanpMjwNRdB kJp7pQmgjJW6neKMcQx7nugZsDxwXmOGa7rt665ax9pZS2oZbQfB39ksPPLeQyN/unsnrj 4V5v+Hd5RrDJfGoOCm81FQsZxi9L2XMD1jYMv4JGGYG90Wji5W/jb/RcFODdZvn0eET3YG 6QmWfqmoXxQAQhsmk+mCDS6Y+Z3pOo8nxwOFdc0HUar01Sz7HDPb7yCHbR5A0d2SkqKHwt 16s6nxsmyIX5qcR9pH3SHaM56F2YJo7ki7bfccoxV/oObBJED/ne9o7ug7fqCw== 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 4Mp2tm3469zMQ3; Thu, 13 Oct 2022 08:36:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 29D8amvw089114; Thu, 13 Oct 2022 08:36:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 29D8am1v089113; Thu, 13 Oct 2022 08:36:48 GMT (envelope-from git) Date: Thu, 13 Oct 2022 08:36:48 GMT Message-Id: <202210130836.29D8am1v089113@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Baptiste Daroussin Subject: git: 48a53cc48495 - main - sort: use asprintf(3) instead of malloc + snprintf(3) List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bapt X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 48a53cc4849555f1a0b805adddb9f517a305a2ae Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1665650208; 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=MjaVDcGzt6/x4asyBVNFiobzQ1eXo1eFwyNBPfsGWSU=; b=QfDJE8D4UjUJ7OM8DweiP9H5/gWPycnJwuk53FIi9d5wWxE1H55ZqO9RtdW64AbZUT81x3 uz8G+bes5PKD7RgSn8FeJZwfRgR1mF7r8xKNK9mm5DdoI/k8oynlUUFidGKlPEHmvRsO4l vR1yqRv+b111sOnWF03tjaZ8yN89Gwm67kitzF8Wu8wfNKl4IK3oM6bqdFpRAJWFAqs9oj NbsThU3OMknUBwes1i9gVSX5quCcqxrsJZ2J9qbwTORu9ZV/+IrkNe0+5W1tFB4MQmB2ny 3prySz5YxFRxwT6inYmo1d/BRXAH8DYzbqmrgiWo+YX62HkV+rn+OmF0A3MPjQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1665650208; a=rsa-sha256; cv=none; b=oRYy7S2qTLlHID/831/vjbHe6LQPzZv9W2Tq7GCacfCnGnj49apktEDVHWKrVRyMb/GH6s EahRMNncAlJdQ1ipQ3AmLy8nl1q9IDEYX/eW1Y6e2jmg4u28+w8QmEp33Hft1bHkzWsc9H CPeBGg/jKBD5K7+zgRjh9QVx1kgnlaVIBfXw4G4yanRsd+FAobmH1VQ41mUfAH9xbhADoU vgjoFpai7h6nUvE/Y57XcgynBniK6m/jBqT0hYEL5woIHuPdq4E7cSpA23Wm8ggpU9pGCP vZSbalr/0mTMdprT7JKFSXFqlduD6bxl0PxzTTH8mclq9KXc+dglaws3axLdvg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=48a53cc4849555f1a0b805adddb9f517a305a2ae commit 48a53cc4849555f1a0b805adddb9f517a305a2ae Author: Baptiste Daroussin AuthorDate: 2022-10-13 08:34:57 +0000 Commit: Baptiste Daroussin CommitDate: 2022-10-13 08:34:57 +0000 sort: use asprintf(3) instead of malloc + snprintf(3) --- usr.bin/sort/file.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/usr.bin/sort/file.c b/usr.bin/sort/file.c index c390b4c2a71f..05058a2509b5 100644 --- a/usr.bin/sort/file.c +++ b/usr.bin/sort/file.c @@ -538,28 +538,26 @@ openfile(const char *fn, const char *mode) S_IRGRP | S_IROTH); if (is_tmp && (compress_program != NULL)) { + int r; char *cmd; - size_t cmdsz; - - cmdsz = strlen(fn) + 128; - cmd = sort_malloc(cmdsz); fflush(stdout); if (mode[0] == 'r') - snprintf(cmd, cmdsz - 1, "cat %s | %s -d", + r = asprintf(&cmd, "cat %s | %s -d", fn, compress_program); else if (mode[0] == 'w') - snprintf(cmd, cmdsz - 1, "%s > %s", + r = asprintf(&cmd, "%s > %s", compress_program, fn); else err(2, "%s", getstr(7)); + if (r == -1) + err(2, "aspritnf()"); + if ((file = popen(cmd, mode)) == NULL) err(2, NULL); - - sort_free(cmd); - + free(cmd); } else if ((file = fopen(fn, mode)) == NULL) err(2, NULL);