Date: Fri, 12 Jan 2024 15:44:29 GMT From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= <des@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: e2ec8ee02a33 - main - uniq: Clean up and test obsolete options. Message-ID: <202401121544.40CFiT5q076684@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=e2ec8ee02a33e39b8ff86a56e8a1ef5e84ac7e62 commit e2ec8ee02a33e39b8ff86a56e8a1ef5e84ac7e62 Author: Dag-Erling Smørgrav <des@FreeBSD.org> AuthorDate: 2024-01-12 15:40:40 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2024-01-12 15:44:00 +0000 uniq: Clean up and test obsolete options. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D43402 --- usr.bin/uniq/tests/uniq_test.sh | 3 +++ usr.bin/uniq/uniq.c | 14 +++++--------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/usr.bin/uniq/tests/uniq_test.sh b/usr.bin/uniq/tests/uniq_test.sh index 8dc2015734f6..537962eb6513 100755 --- a/usr.bin/uniq/tests/uniq_test.sh +++ b/usr.bin/uniq/tests/uniq_test.sh @@ -74,6 +74,7 @@ skip_fields_head() { skip_fields_body() { printf "1 a\n2 a\n3 b\n4 b\n5 a\n6 a\n" >input printf "1 a\n3 b\n5 a\n" >expected + atf_check_uniq -1 atf_check_uniq -f 1 atf_check_uniq --skip-fields 1 } @@ -85,6 +86,7 @@ skip_fields_tab_head() { skip_fields_tab_body() { printf "1\ta\n2\ta\n3\tb\n4\tb\n5\ta\n6\ta\n" >input printf "1\ta\n3\tb\n5\ta\n" >expected + atf_check_uniq -1 atf_check_uniq -f 1 atf_check_uniq --skip-fields 1 } @@ -107,6 +109,7 @@ skip_chars_head() { skip_chars_body() { printf "1 a\n2 a\n3 b\n4 b\n5 a\n6 a\n" >input printf "1 a\n3 b\n5 a\n" >expected + atf_check_uniq +2 atf_check_uniq -s 2 atf_check_uniq --skip-chars 2 } diff --git a/usr.bin/uniq/uniq.c b/usr.bin/uniq/uniq.c index 0bc9b2b86af3..ef59d7339d0c 100644 --- a/usr.bin/uniq/uniq.c +++ b/usr.bin/uniq/uniq.c @@ -338,29 +338,25 @@ file(const char *name, const char *mode) static void obsolete(char *argv[]) { - int len; - char *ap, *p, *start; + char *ap, *p; while ((ap = *++argv)) { /* Return if "--" or not an option of any form. */ if (ap[0] != '-') { if (ap[0] != '+') return; - } else if (ap[1] == '-') + } else if (ap[1] == '-') { return; + } if (!isdigit((unsigned char)ap[1])) continue; /* * Digit signifies an old-style option. Malloc space for dash, * new option and argument. */ - len = strlen(ap); - if ((start = p = malloc(len + 3)) == NULL) + if (asprintf(&p, "-%c%s", ap[0] == '+' ? 's' : 'f', ap + 1) < 0) err(1, "malloc"); - *p++ = '-'; - *p++ = ap[0] == '+' ? 's' : 'f'; - (void)strcpy(p, ap + 1); - *argv = start; + *argv = p; } }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202401121544.40CFiT5q076684>