diff options
author | Baptiste Daroussin <bapt@FreeBSD.org> | 2022-10-13 08:34:57 +0000 |
---|---|---|
committer | Baptiste Daroussin <bapt@FreeBSD.org> | 2022-10-13 08:34:57 +0000 |
commit | 48a53cc4849555f1a0b805adddb9f517a305a2ae (patch) | |
tree | 4f259e0153f34f77ac3391fc97c833d019c7e2ad | |
parent | 958b0d46425395f8f4606ac5d12681d623282e9d (diff) | |
download | src-48a53cc4849555f1a0b805adddb9f517a305a2ae.tar.gz src-48a53cc4849555f1a0b805adddb9f517a305a2ae.zip |
sort: use asprintf(3) instead of malloc + snprintf(3)
-rw-r--r-- | usr.bin/sort/file.c | 16 |
1 files 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); |