aboutsummaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorDag-Erling Smørgrav <des@FreeBSD.org>2023-07-19 14:25:56 +0000
committerDag-Erling Smørgrav <des@FreeBSD.org>2023-07-19 14:47:23 +0000
commita122c3c49278f8247296fdc1c097129e4862e472 (patch)
treeddc5610c1cfec1f0a47f8bc6bedf7cc53ca290f8 /usr.bin
parent6f251ef228e6ea3891cd7364c1e6d161297a2f90 (diff)
downloadsrc-a122c3c49278f8247296fdc1c097129e4862e472.tar.gz
src-a122c3c49278f8247296fdc1c097129e4862e472.zip
unifdef: Fix case where a multiline comment follows a directive.
Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D41026
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/unifdef/tests/Makefile1
-rw-r--r--usr.bin/unifdef/tests/unifdef_test.sh22
-rw-r--r--usr.bin/unifdef/unifdef.c5
3 files changed, 26 insertions, 2 deletions
diff --git a/usr.bin/unifdef/tests/Makefile b/usr.bin/unifdef/tests/Makefile
index ddcfbdc6146e..a27c58285c20 100644
--- a/usr.bin/unifdef/tests/Makefile
+++ b/usr.bin/unifdef/tests/Makefile
@@ -2,6 +2,7 @@
PACKAGE= tests
+ATF_TESTS_SH= unifdef_test
NETBSD_ATF_TESTS_SH= basic_test
${PACKAGE}FILES+= d_basic.in
diff --git a/usr.bin/unifdef/tests/unifdef_test.sh b/usr.bin/unifdef/tests/unifdef_test.sh
new file mode 100644
index 000000000000..98adef3adfdc
--- /dev/null
+++ b/usr.bin/unifdef/tests/unifdef_test.sh
@@ -0,0 +1,22 @@
+#
+# Copyright (c) 2023 Klara, Inc.
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+
+atf_test_case hash_comment
+hash_comment_head() {
+ atf_set descr "multiline comment follows directive"
+}
+hash_comment_body() {
+ cat >f <<EOF
+#if FOO
+#endif /*
+*/
+EOF
+ atf_check -o file:f unifdef <f
+}
+
+atf_init_test_cases() {
+ atf_add_test_case hash_comment
+}
diff --git a/usr.bin/unifdef/unifdef.c b/usr.bin/unifdef/unifdef.c
index d8616016f53d..598c66e3ab06 100644
--- a/usr.bin/unifdef/unifdef.c
+++ b/usr.bin/unifdef/unifdef.c
@@ -886,8 +886,9 @@ parseline(void)
retval = LT_ELIF;
}
/* the following can happen if the last line of the file lacks a
- newline or if there is too much whitespace in a directive */
- if (linestate == LS_HASH) {
+ newline or if there is too much whitespace in a directive,
+ or if a directive is followed by a multiline comment */
+ if (linestate == LS_HASH && !incomment) {
long len = cp - tline;
if (fgets(tline + len, MAXLINE - len, input) == NULL) {
if (ferror(input))