diff options
Diffstat (limited to 'usr.bin')
139 files changed, 5390 insertions, 0 deletions
diff --git a/usr.bin/cc/t_ctype_abuse.sh b/usr.bin/cc/t_ctype_abuse.sh new file mode 100644 index 000000000000..e7c7c74d1220 --- /dev/null +++ b/usr.bin/cc/t_ctype_abuse.sh @@ -0,0 +1,124 @@ +# $NetBSD: t_ctype_abuse.sh,v 1.1 2024/12/18 02:47:00 riastradh Exp $ +# +# Copyright (c) 2024 The NetBSD Foundation, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +ctype_abuse_head() +{ + local ctypefn reftype desc + + ctypefn=$1 + reftype=$2 + + case $reftype in + var) desc="variable";; + ptr) desc="pointer dereference";; + array) desc="array element";; + funcall) + desc="function call";; + esac + + atf_set "descr" "Test that $ctypefn warns on $desc of type char" + atf_set "require.progs" "cc" +} + +ctype_abuse_body() +{ + local ctypefn reftype + + ctypefn=$1 + reftype=$2 + + case $reftype in + var) decl='x'; ref='x';; + ptr) decl='*x'; ref='*x';; + array) decl='x[]'; ref='x[0]';; + funcall) + decl='f(void)'; ref='f()';; + esac + + cat >test.c <<EOF +#include <ctype.h> + +extern char $decl; + +int +g(void) +{ + + return $ctypefn($ref); +} +EOF + case $reftype in + var) atf_expect_fail 'PR lib/58912: ctype(3) abuse detection' \ + ' fails for variable references';; + esac + atf_check -s not-exit:0 \ + -e match:'array subscript has type.*char.*-W.*char-subscripts' \ + cc -c -Wall -Werror test.c +} + +ctype_abuse_tests() +{ + local ctypefn reftype tc + + for ctypefn in \ + isalpha \ + isupper \ + islower \ + isdigit \ + isxdigit \ + isalnum \ + isspace \ + ispunct \ + isprint \ + isgraph \ + iscntrl \ + isblank \ + toupper \ + tolower \ + # end of ctypefn enumeration + do + for reftype in var ptr array funcall; do + tc=${ctypefn}_${reftype} + eval "atf_test_case $tc" + eval "${tc}_head() + { + ctype_abuse_head $ctypefn $reftype + }" + eval "${tc}_body() + { + ctype_abuse_body $ctypefn $reftype + }" + atf_add_test_case $tc + done + done +} + +atf_init_test_cases() +{ + + ctype_abuse_tests +} diff --git a/usr.bin/cc/t_libm_cabs.sh b/usr.bin/cc/t_libm_cabs.sh new file mode 100644 index 000000000000..85cce3f19228 --- /dev/null +++ b/usr.bin/cc/t_libm_cabs.sh @@ -0,0 +1,57 @@ +# $NetBSD: t_libm_cabs.sh,v 1.1 2026/01/27 20:01:47 mrg Exp $ +# +# Copyright (c) 2026 Matthew R. Green +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. + + +atf_test_case libm_cabs +libm_cabs_head() { + atf_set "descr" "compile using __builtin_cabsl(3) which should be renamed" + atf_set "require.progs" "cc" +} + +# +# Simple program that misses including <complex.h> so that the renames +# GCC itself is supposed to be doing are also applied, which makes their +# uses in libgfortran use the correct symbols. The use of +# "__builtin_cabsl" should become "__c99_cabsl". +# +libm_cabs_body() { + cat > cabsl.c << EOF +long double my_foo(long double _Complex); +long double +my_foo(long double _Complex z) +{ + return __builtin_cabsl(z); +} +EOF + atf_check -s exit:0 -o ignore -e ignore cc -O3 -c cabsl.c + atf_check -s exit:0 -o match:__c99_cabsl -e empty objdump -dr cabsl.o +} + +atf_init_test_cases() +{ + + atf_add_test_case libm_cabs +} diff --git a/usr.bin/cc/t_pthread_abuse.sh b/usr.bin/cc/t_pthread_abuse.sh new file mode 100644 index 000000000000..caf88e60557f --- /dev/null +++ b/usr.bin/cc/t_pthread_abuse.sh @@ -0,0 +1,79 @@ +# $NetBSD: t_pthread_abuse.sh,v 1.1 2025/10/06 13:11:56 riastradh Exp $ +# +# Copyright (c) 2025 The NetBSD Foundation, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +pthread_abuse_head() +{ + + atf_set "descr" \ + "Test that pthread_create calls without -lpthread fail to link" + atf_set "require.progs" "cc" +} +pthread_abuse_body() +{ + + cat >test.c <<'EOF' +#include <err.h> +#include <pthread.h> +#include <stdlib.h> + +static void * +start(void *cookie) +{ + return cookie; +} + +int +main(void) +{ + int cookie = 123; + pthread_t t; + void *result; + int error; + + error = pthread_create(&t, NULL, &start, &cookie); + if (error) + errc(EXIT_FAILURE, error, "pthread_create"); + error = pthread_join(t, &result); + if (error) + errc(EXIT_FAILURE, error, "pthread_join"); + return (result == &cookie ? 0 : EXIT_FAILURE); +} +EOF + atf_check -s not-exit:0 \ + -e match:'undefined reference to.*pthread_create' \ + cc -o test test.c + atf_check cc -o test test.c -lpthread + atf_check ./test + atf_check cc -o test test.c -pthread + atf_check ./test +} + +atf_init_test_cases() +{ + + atf_add_test_case pthread_abuse +} diff --git a/usr.bin/diff/functionname.in b/usr.bin/diff/functionname.in new file mode 100644 index 000000000000..7b4c50c86cd9 --- /dev/null +++ b/usr.bin/diff/functionname.in @@ -0,0 +1,29 @@ +static void +doSomethingThenPrintHello(int test) +{ + test = test << 4; + if (test % 8 == 6) { + return; + } + + print("goodbye\n"); +} + + +- (long) readOffset:(FILE*)file +{ + if( version >= 11){ + long offset; + fread(&offset, sizeof(long), 1, file); + return offset; + } else { + int offset; + fread(&offset, sizeof(int), 1, file); + return offset; + } +} + ++ (BOOL) isEdible:(NSString *)mushroom +{ + return TRUE; +} diff --git a/usr.bin/diff/functionname_c.in b/usr.bin/diff/functionname_c.in new file mode 100644 index 000000000000..84f6846783ca --- /dev/null +++ b/usr.bin/diff/functionname_c.in @@ -0,0 +1,29 @@ +static void +doSomethingThenPrintHello(int test) +{ + test = test << 4; + if (test % 8 == 6) { + return; + } + + print("hello\n"); +} + + +- (long) readOffset:(FILE*)file +{ + if( version >= 11){ + long offset; + fread(&offset, sizeof(long), 1, file); + return offset; + } else { + int offset; + fread(&offset, sizeof(int), 1, file); + return offset; + } +} + ++ (BOOL) isEdible:(NSString *)mushroom +{ + return TRUE; +} diff --git a/usr.bin/diff/functionname_c.out b/usr.bin/diff/functionname_c.out new file mode 100644 index 000000000000..b17ce05d04ca --- /dev/null +++ b/usr.bin/diff/functionname_c.out @@ -0,0 +1,11 @@ +--- functionname.in ++++ functionname_c.in +@@ -6,7 +6,7 @@ doSomethingThenPrintHello(int test) + return; + } + +- print("goodbye\n"); ++ print("hello\n"); + } + + diff --git a/usr.bin/diff/header.out b/usr.bin/diff/header.out new file mode 100644 index 000000000000..2e1665a30e6d --- /dev/null +++ b/usr.bin/diff/header.out @@ -0,0 +1,4 @@ +--- empty 2015-04-03 01:02:03.000000000 +0000 ++++ hello 2016-12-22 11:22:33.000000000 +0000 +@@ -0,0 +1 @@ ++hello diff --git a/usr.bin/diff/header_ns.out b/usr.bin/diff/header_ns.out new file mode 100644 index 000000000000..b1316dfc12b9 --- /dev/null +++ b/usr.bin/diff/header_ns.out @@ -0,0 +1,4 @@ +--- empty 2015-04-03 01:02:03.123456789 +0000 ++++ hello 2016-12-22 11:22:33.987654321 +0000 +@@ -0,0 +1 @@ ++hello diff --git a/usr.bin/diff/input1.in b/usr.bin/diff/input1.in new file mode 100644 index 000000000000..3892e8400f86 --- /dev/null +++ b/usr.bin/diff/input1.in @@ -0,0 +1,2 @@ +Simple input file designed +to be able to test diff diff --git a/usr.bin/diff/input2.in b/usr.bin/diff/input2.in new file mode 100644 index 000000000000..c38b487353a7 --- /dev/null +++ b/usr.bin/diff/input2.in @@ -0,0 +1,3 @@ +Simple input file designed +and written +to be able to test diff utility diff --git a/usr.bin/diff/input_c1.in b/usr.bin/diff/input_c1.in new file mode 100644 index 000000000000..d39dfbdc511b --- /dev/null +++ b/usr.bin/diff/input_c1.in @@ -0,0 +1,15 @@ +/* + * A comment + * + * And another bla + * + * And yet another + */ + +int +main(void) +{ + printf("something"); + + return (0); +} diff --git a/usr.bin/diff/input_c2.in b/usr.bin/diff/input_c2.in new file mode 100644 index 000000000000..933ec67dc175 --- /dev/null +++ b/usr.bin/diff/input_c2.in @@ -0,0 +1,16 @@ +/* + * A comment + * + * And another bla + * + * and yet another + */ + +int +main(void) +{ + + printf("something"); + + return (0); +} diff --git a/usr.bin/diff/simple.out b/usr.bin/diff/simple.out new file mode 100644 index 000000000000..fcbcaa041e8c --- /dev/null +++ b/usr.bin/diff/simple.out @@ -0,0 +1,5 @@ +2c2,3 +< to be able to test diff +--- +> and written +> to be able to test diff utility diff --git a/usr.bin/diff/simple_b.out b/usr.bin/diff/simple_b.out new file mode 100644 index 000000000000..704be9d621a8 --- /dev/null +++ b/usr.bin/diff/simple_b.out @@ -0,0 +1,6 @@ +6c6 +< * And yet another +--- +> * and yet another +11a12 +> diff --git a/usr.bin/diff/simple_e.out b/usr.bin/diff/simple_e.out new file mode 100644 index 000000000000..0c7e2b5c752b --- /dev/null +++ b/usr.bin/diff/simple_e.out @@ -0,0 +1,4 @@ +2c +and written +to be able to test diff utility +. diff --git a/usr.bin/diff/simple_i.out b/usr.bin/diff/simple_i.out new file mode 100644 index 000000000000..9edc1f98d72d --- /dev/null +++ b/usr.bin/diff/simple_i.out @@ -0,0 +1,6 @@ +4c4 +< * And another bla +--- +> * And another bla +11a12 +> diff --git a/usr.bin/diff/simple_n.out b/usr.bin/diff/simple_n.out new file mode 100644 index 000000000000..33ca7090cf97 --- /dev/null +++ b/usr.bin/diff/simple_n.out @@ -0,0 +1,4 @@ +d2 1 +a2 2 +and written +to be able to test diff utility diff --git a/usr.bin/diff/simple_p.out b/usr.bin/diff/simple_p.out new file mode 100644 index 000000000000..f5aebb0d1199 --- /dev/null +++ b/usr.bin/diff/simple_p.out @@ -0,0 +1,34 @@ +*** input_c1.in +--- input_c2.in +*************** +*** 1,14 **** + /* + * A comment + * +! * And another bla + * +! * And yet another + */ + + int + main(void) + { + printf("something"); + + return (0); +--- 1,15 ---- + /* + * A comment + * +! * And another bla + * +! * and yet another + */ + + int + main(void) + { ++ + printf("something"); + + return (0); diff --git a/usr.bin/diff/simple_u.out b/usr.bin/diff/simple_u.out new file mode 100644 index 000000000000..f341987ebec6 --- /dev/null +++ b/usr.bin/diff/simple_u.out @@ -0,0 +1,7 @@ +--- input1 ++++ input2 +@@ -1,2 +1,3 @@ + Simple input file designed +-to be able to test diff ++and written ++to be able to test diff utility diff --git a/usr.bin/diff/simple_w.out b/usr.bin/diff/simple_w.out new file mode 100644 index 000000000000..704be9d621a8 --- /dev/null +++ b/usr.bin/diff/simple_w.out @@ -0,0 +1,6 @@ +6c6 +< * And yet another +--- +> * and yet another +11a12 +> diff --git a/usr.bin/diff/unified_9999.out b/usr.bin/diff/unified_9999.out new file mode 100644 index 000000000000..0f9303fbdc7c --- /dev/null +++ b/usr.bin/diff/unified_9999.out @@ -0,0 +1,21 @@ +--- input_c1.in ++++ input_c2.in +@@ -1,15 +1,16 @@ + /* + * A comment + * +- * And another bla ++ * And another bla + * +- * And yet another ++ * and yet another + */ + + int + main(void) + { ++ + printf("something"); + + return (0); + } diff --git a/usr.bin/diff/unified_p.out b/usr.bin/diff/unified_p.out new file mode 100644 index 000000000000..938b07890fbc --- /dev/null +++ b/usr.bin/diff/unified_p.out @@ -0,0 +1,20 @@ +--- input_c1.in ++++ input_c2.in +@@ -1,14 +1,15 @@ + /* + * A comment + * +- * And another bla ++ * And another bla + * +- * And yet another ++ * and yet another + */ + + int + main(void) + { ++ + printf("something"); + + return (0); diff --git a/usr.bin/error/Makefile b/usr.bin/error/Makefile new file mode 100644 index 000000000000..6d3e2e72fbc9 --- /dev/null +++ b/usr.bin/error/Makefile @@ -0,0 +1,6 @@ +# $NetBSD: Makefile,v 1.1 2023/08/26 10:06:16 rillig Exp $ + +TESTSDIR= ${TESTSBASE}/usr.bin/error +TESTS_SH= t_error + +.include <bsd.test.mk> diff --git a/usr.bin/error/t_error.sh b/usr.bin/error/t_error.sh new file mode 100644 index 000000000000..89f25e90b4e4 --- /dev/null +++ b/usr.bin/error/t_error.sh @@ -0,0 +1,101 @@ +# $NetBSD: t_error.sh,v 1.1 2023/08/26 10:06:16 rillig Exp $ +# +# Copyright (c) 2023 The NetBSD Foundation, Inc. +# All rights reserved. +# +# This code is derived from software contributed to The NetBSD Foundation +# by Roland Illig. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +create_file() { + local fn="$1"; shift + printf '%s\n' "$@" > "$fn" +} + +atf_test_case cc +cc_body() { + create_file code.c \ + 'goto error' + create_file err \ + 'code.c:1: error: syntax error' + create_file expected \ + '/*###1 [cc] error: syntax error%%%*/' \ + 'goto error' + + atf_check -o ignore \ + error err + atf_check -o 'file:expected' cat code.c +} + +atf_test_case f77 +f77_body() { + create_file code.f \ + 'doi=1,1,1' + create_file err \ + 'Compiler error line 1 of code.f: syntax error' + create_file expected \ + 'C###1 [f77] Compiler error line 1 of code.f syntax error%%%' \ + 'doi=1,1,1' + + atf_check -o ignore \ + error err + atf_check -o 'file:expected' cat code.f +} + +atf_test_case lint +lint_body() { + create_file code.c \ + 'goto error' + create_file err \ + 'code.c(1): syntax error' + create_file expected \ + '/*###1 [lint] syntax error%%%*/' \ + 'goto error' + + atf_check -o ignore \ + error err + atf_check -o 'file:expected' cat code.c +} + +atf_test_case mod2 +mod2_body() { + create_file code.m2 \ + 'END.' + create_file err \ + 'File code.m2, line 1: missing BEGIN' + create_file expected \ + '(*###1 [mod2] missing BEGIN%%%*)' \ + 'END.' + + atf_check -o ignore \ + error err + atf_check -o 'file:expected' cat code.m2 +} + +atf_init_test_cases() { + atf_add_test_case cc + atf_add_test_case f77 + atf_add_test_case lint + atf_add_test_case mod2 +} diff --git a/usr.bin/ftp/Makefile b/usr.bin/ftp/Makefile new file mode 100644 index 000000000000..8d47e55379fc --- /dev/null +++ b/usr.bin/ftp/Makefile @@ -0,0 +1,15 @@ +# $NetBSD: Makefile,v 1.1 2024/10/12 22:19:37 riastradh Exp $ + +.include <bsd.own.mk> + +TESTSDIR= ${TESTSBASE}/usr.bin/ftp +TESTS_SH= t_custom_headers + +SCRIPTSDIR= ${TESTSDIR} +SCRIPTS+= custom_headers.sh + +# Keep the .sh suffix because we use it to trigger cgi-bin handling in +# bozohttpd (rather silly but it's easier that way). +SCRIPTSNAME_custom_headers.sh= custom_headers.sh + +.include <bsd.test.mk> diff --git a/usr.bin/ftp/custom_headers.sh b/usr.bin/ftp/custom_headers.sh new file mode 100644 index 000000000000..e364ef0e784e --- /dev/null +++ b/usr.bin/ftp/custom_headers.sh @@ -0,0 +1,36 @@ +#! /bin/sh +# +# $NetBSD: custom_headers.sh,v 1.1 2024/10/12 22:19:37 riastradh Exp $ +# +# Copyright (c) 2024 The NetBSD Foundation, Inc. +# All rights reserved. +# +# This code is derived from software contributed to The NetBSD Foundation +# by Sunil Nimmagadda. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +echo "Content-type: text/plain; charset=utf-8" +echo "" +echo "HTTP_X_ORIGIN=$HTTP_X_ORIGIN" +echo "HTTP_X_RATE_LIMIT=$HTTP_X_RATE_LIMIT" diff --git a/usr.bin/ftp/t_custom_headers.sh b/usr.bin/ftp/t_custom_headers.sh new file mode 100644 index 000000000000..bdf185512f68 --- /dev/null +++ b/usr.bin/ftp/t_custom_headers.sh @@ -0,0 +1,67 @@ +# $NetBSD: t_custom_headers.sh,v 1.1 2024/10/12 22:19:37 riastradh Exp $ +# +# Copyright (c) 2024 The NetBSD Foundation, Inc. +# All rights reserved. +# +# This code is derived from software contributed to The NetBSD Foundation +# by Sunil Nimmagadda. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +atf_test_case custom_headers cleanup +custom_headers_head() +{ + atf_require_prog ftp + atf_set "descr" "Check for custom HTTP headers" +} + +HTTPD_PID=./.__httpd.pid +custom_headers_body() +{ + # start httpd in daemon mode + atf_check -s exit:0 \ + /usr/libexec/httpd -P $HTTPD_PID -I 8080 -b -C .sh /bin/sh \ + -c "$(atf_get_srcdir)" . + + atf_check \ + -o inline:'HTTP_X_ORIGIN=example.com\nHTTP_X_RATE_LIMIT=1000\n' \ + ftp -V -o - \ + -H 'X-Origin: example.com' \ + -H 'X-Rate-Limit: 1000' \ + http://127.0.0.1:8080/cgi-bin/custom_headers.sh +} + +custom_headers_cleanup() +{ + if [ -f "$HTTPD_PID" ]; then + echo kill -9 "$(cat $HTTPD_PID)" + kill -9 "$(cat $HTTPD_PID)" + echo '# wait for httpd to exit' + sleep 1 + fi +} + +atf_init_test_cases() +{ + atf_add_test_case custom_headers +} diff --git a/usr.bin/gcov/Makefile b/usr.bin/gcov/Makefile new file mode 100644 index 000000000000..6828aac4b00e --- /dev/null +++ b/usr.bin/gcov/Makefile @@ -0,0 +1,7 @@ +# $NetBSD: Makefile,v 1.1 2025/01/18 22:31:22 rillig Exp $ + +TESTSDIR= ${TESTSBASE}/usr.bin/gcov + +TESTS_SH= t_gcov + +.include <bsd.test.mk> diff --git a/usr.bin/gcov/t_gcov.sh b/usr.bin/gcov/t_gcov.sh new file mode 100644 index 000000000000..7895a9b9adf0 --- /dev/null +++ b/usr.bin/gcov/t_gcov.sh @@ -0,0 +1,104 @@ +# $NetBSD: t_gcov.sh,v 1.1 2025/01/18 22:31:22 rillig Exp $ +# +# Copyright (c) 2025 The NetBSD Foundation, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +after_exec_head() +{ +} +after_exec_body() +{ + atf_require_prog cat + atf_require_prog gcc + atf_require_prog gcov + atf_require_prog grep + + cat <<EOF >prog.c +#include <unistd.h> + +int +main(void) +{ + pid_t pid = vfork(); + switch (pid) { + case 0: + execl("/bin/sh", "sh", "-c", ":", (const char *)0); + /* FALLTHROUGH */ + case -1: + write(2, "error\n", 6); + _exit(1); + } + + write(1, "reached\n", 8); + return 0; +} +EOF + + cat <<EOF >prog.c.gcov.expected + -: 0:Source:prog.c + -: 0:Graph:prog.gcno + -: 0:Data:prog.gcda + -: 0:Runs:1 + -: 1:#include <unistd.h> + -: 2: + -: 3:int + 1: 4:main(void) + -: 5:{ + 1: 6: pid_t pid = vfork(); + 1: 7: switch (pid) { + 1: 8: case 0: + 1: 9: execl("/bin/sh", "sh", "-c", ":", (const char *)0); + -: 10: /* FALLTHROUGH */ + #####: 11: case -1: + #####: 12: write(2, "error\n", 6); + #####: 13: _exit(1); + -: 14: } + -: 15: + #####: 16: write(1, "reached\n", 8); + #####: 17: return 0; + -: 18:} +EOF + + atf_check \ + gcc --coverage -c prog.c + atf_check \ + gcc --coverage -o prog prog.o + atf_check -o inline:'reached\n' \ + ./prog + atf_check -o ignore \ + gcov prog.c + + atf_check -o file:prog.c.gcov.expected \ + cat prog.c.gcov + + # FIXME: The code was reached once but is reported as unreached. + atf_check -o ignore \ + grep "#####.*reached" prog.c.gcov +} + +atf_init_test_cases() +{ + atf_add_test_case after_exec +} diff --git a/usr.bin/mtree/Makefile b/usr.bin/mtree/Makefile new file mode 100644 index 000000000000..a7f091f3832f --- /dev/null +++ b/usr.bin/mtree/Makefile @@ -0,0 +1,8 @@ +# $NetBSD: Makefile,v 1.1 2024/01/25 00:30:57 riastradh Exp $ +# + +TESTSDIR= ${TESTSBASE}/usr.bin/mtree + +TESTS_SH+= t_sets + +.include <bsd.test.mk> diff --git a/usr.bin/mtree/t_sets.sh b/usr.bin/mtree/t_sets.sh new file mode 100644 index 000000000000..c9f56956bfdd --- /dev/null +++ b/usr.bin/mtree/t_sets.sh @@ -0,0 +1,126 @@ +# $NetBSD: t_sets.sh,v 1.9 2024/05/10 03:29:47 riastradh Exp $ +# +# Copyright (c) 2024 The NetBSD Foundation, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +check_mtree() +{ + local set=$1 + + cd / + atf_check -o empty -s exit:0 \ + mtree -e </etc/mtree/set."$set" +} + +set_case() +{ + local set=$1 + + eval "set_${set}_head() { atf_set descr \"/etc/mtree/set.${set}\"; }" + eval "set_${set}_body() { check_mtree ${set}; }" + eval "set_${set}_defined=" +} + +set_case base +set_case base32 +set_case base64 +set_case comp +set_case debug +set_case debug32 +set_case debug64 +set_case dtb +#set_case etc +set_case games +set_case gpufw +set_case man +set_case manhtml +set_case misc +set_case modules +set_case rescue +set_case tests +set_case text +set_case xbase +set_case xcomp +set_case xdebug +#set_case xetc +set_case xfont +set_case xserver + +sets_unknown= + +sets_unknown_head() +{ + atf_set descr "Verify this tests lists all sets" +} +sets_unknown_body() +{ + test -z "$sets_unknown" || atf_fail "Unknown sets: ${sets_unknown}" +} + +atf_init_test_cases() +{ + local mtree set defined + + atf_add_test_case sets_unknown + + # base is always installed -- hard-code this in case we make a + # mistake with the automatic set detection. + atf_add_test_case set_base + + # Test all of the sets that are installed, except for some + # special cases. + for mtree in /etc/mtree/set.*; do + set=${mtree#/etc/mtree/set.} + case $set in + base) # Handled above already. + continue + ;; + dtb) + # contents of this set go to the boot partition, + # which may not be mounted during normal operation + if [ ! -d /boot/dtb ]; then + continue; + fi + ;; + etc|xetc) + # etc and xetc have files that may be modified + # on installation, and also contain log files, + # so let's skip them for now. + continue + ;; + *) ;; + esac + + # If we have a test for this set, add it. Otherwise, + # add it to the unknown list to make the test suite + # fail. + eval 'defined=${set_'"$set"'_defined+yes}' + if [ -n "$defined" ]; then + atf_add_test_case set_"${set}" + else + sets_unknown="${sets_unknown}${sets_unknown:+ }${set}" + fi + done +} diff --git a/usr.bin/netpgpkeys/Makefile b/usr.bin/netpgpkeys/Makefile new file mode 100644 index 000000000000..7852906c3ee7 --- /dev/null +++ b/usr.bin/netpgpkeys/Makefile @@ -0,0 +1,13 @@ +# $NetBSD: Makefile,v 1.2 2026/01/29 16:14:45 wiz Exp $ + +.include <bsd.own.mk> + +TESTSDIR= ${TESTSBASE}/usr.bin/netpgpkeys + +TESTS_SH+= t_netpgpkeys + +FILESDIR= ${TESTSDIR}/data +FILES+= data/testkey-ec.pub +FILES+= data/testkey-rsa.pub + +.include <bsd.test.mk> diff --git a/usr.bin/netpgpkeys/data/testkey-ec.pub b/usr.bin/netpgpkeys/data/testkey-ec.pub Binary files differnew file mode 100644 index 000000000000..aff1af8376da --- /dev/null +++ b/usr.bin/netpgpkeys/data/testkey-ec.pub diff --git a/usr.bin/netpgpkeys/data/testkey-rsa.pub b/usr.bin/netpgpkeys/data/testkey-rsa.pub Binary files differnew file mode 100644 index 000000000000..d4bec383e5ea --- /dev/null +++ b/usr.bin/netpgpkeys/data/testkey-rsa.pub diff --git a/usr.bin/netpgpkeys/t_netpgpkeys.sh b/usr.bin/netpgpkeys/t_netpgpkeys.sh new file mode 100644 index 000000000000..08d01a7fe98e --- /dev/null +++ b/usr.bin/netpgpkeys/t_netpgpkeys.sh @@ -0,0 +1,81 @@ +#! /bin/sh + +# $NetBSD: t_netpgpkeys.sh,v 1.3 2026/01/31 22:35:10 wiz Exp $ + +# +# Copyright (c) 2026 The NetBSD Foundation, Inc. +# All rights reserved. +# +# This code is derived from software contributed to The NetBSD Foundation +# by Thomas Klausner <wiz@NetBSD.org> +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +cleanup_core() { + local prog + + prog=$1 + test -f "${prog}.core" || return 0 + readelf -rs "/usr/bin/${prog}" + gdb -batch -ex bt -ex 'info registers' -ex disas \ + "/usr/bin/${prog}" "${prog}.core" +} + +# Test set 1 (rsa key) for netpgpkeys +atf_test_case netpgpkeys_testset_1_rsa_keys + +netpgpkeys_testset_1_rsa_keys_head() { + atf_set "descr" "Test set 1 (rsa_keys) for netpgpkeys" +} +netpgpkeys_testset_1_rsa_keys_body() { + atf_expect_fail "PR bin/59936 - does not support keys generated by gnugp2" + # TODO: fix netpgpkeys so it doesn't need an empty keyring + atf_check touch pubring.gpg + atf_check netpgpkeys --keyring pubring.gpg \ + --import-key "$(atf_get_srcdir)"/data/testkey-rsa.pub +} + +# Test set 2 (elliptic curve keys) for netpgpkeys +atf_test_case netpgpkeys_testset_2_ec_keys cleanup + +netpgpkeys_testset_2_ec_keys_head() { + atf_set "descr" "Test set 2 (ec_keys) for netpgpkeys" +} +netpgpkeys_testset_2_ec_keys_body() { + atf_expect_fail "PR bin/59936 - does not support keys generated by gnugp2 - dumps core for EC keys" + # TODO: fix netpgpkeys so it doesn't need an empty keyring + atf_check touch pubring.gpg + atf_check netpgpkeys --keyring pubring.gpg \ + --import-key "$(atf_get_srcdir)"/data/testkey-ec.pub \ + --coredumps +} + +netpgpkeys_testset_2_ec_keys_cleanup() { + cleanup_core netpgpkeys +} + +# all test sets +atf_init_test_cases() { + atf_add_test_case netpgpkeys_testset_1_rsa_keys + atf_add_test_case netpgpkeys_testset_2_ec_keys +} diff --git a/usr.bin/netpgpverify/data/D5B22A28.pub b/usr.bin/netpgpverify/data/D5B22A28.pub Binary files differnew file mode 100644 index 000000000000..3e41c990e290 --- /dev/null +++ b/usr.bin/netpgpverify/data/D5B22A28.pub diff --git a/usr.bin/netpgpverify/data/D5B22A28.secret b/usr.bin/netpgpverify/data/D5B22A28.secret Binary files differnew file mode 100644 index 000000000000..2c9f1fb35b72 --- /dev/null +++ b/usr.bin/netpgpverify/data/D5B22A28.secret diff --git a/usr.bin/netpgpverify/data/NetBSD-6.0_hashes.asc.gz b/usr.bin/netpgpverify/data/NetBSD-6.0_hashes.asc.gz Binary files differnew file mode 100644 index 000000000000..b1499aaeb80e --- /dev/null +++ b/usr.bin/netpgpverify/data/NetBSD-6.0_hashes.asc.gz diff --git a/usr.bin/netpgpverify/data/a.gpg b/usr.bin/netpgpverify/data/a.gpg Binary files differnew file mode 100644 index 000000000000..4041a0aa61b0 --- /dev/null +++ b/usr.bin/netpgpverify/data/a.gpg diff --git a/usr.bin/netpgpverify/data/b.gpg b/usr.bin/netpgpverify/data/b.gpg Binary files differnew file mode 100644 index 000000000000..6934bddc429a --- /dev/null +++ b/usr.bin/netpgpverify/data/b.gpg diff --git a/usr.bin/netpgpverify/data/det b/usr.bin/netpgpverify/data/det new file mode 100644 index 000000000000..04dc803533a2 --- /dev/null +++ b/usr.bin/netpgpverify/data/det @@ -0,0 +1,16 @@ +To Do +===== +tests with -k sig +detached sigs +DSA + +Done +==== +basics +localise pgp_read_packets +fix lint +WARNS=5 +lib man page +prog man page +do we do it statically linked as well? +multiple files in netpgpverify diff --git a/usr.bin/netpgpverify/data/det.sig b/usr.bin/netpgpverify/data/det.sig Binary files differnew file mode 100644 index 000000000000..5bf66e7878cf --- /dev/null +++ b/usr.bin/netpgpverify/data/det.sig diff --git a/usr.bin/netpgpverify/data/dsa-pubring.gpg b/usr.bin/netpgpverify/data/dsa-pubring.gpg Binary files differnew file mode 100644 index 000000000000..a941a8fa5ee5 --- /dev/null +++ b/usr.bin/netpgpverify/data/dsa-pubring.gpg diff --git a/usr.bin/netpgpverify/data/expected16 b/usr.bin/netpgpverify/data/expected16 new file mode 100644 index 000000000000..958c7b960389 --- /dev/null +++ b/usr.bin/netpgpverify/data/expected16 @@ -0,0 +1,8 @@ +Good signature for b.gpg made Mon Sep 10 00:15:38 2012 +signature 2048/RSA (Encrypt or Sign) 1b68dcfcc0596823 2004-01-12 +fingerprint d415 9deb 336d e4cc cdfa 00cd 1b68 dcfc c059 6823 +uid Alistair Crooks <agc@alistaircrooks.com> +uid Alistair Crooks <agc@pkgsrc.org> +uid Alistair Crooks <agc@netbsd.org> +uid Alistair Crooks <agc@netflix.com> + diff --git a/usr.bin/netpgpverify/data/expected17 b/usr.bin/netpgpverify/data/expected17 new file mode 100644 index 000000000000..0ea49e043f65 --- /dev/null +++ b/usr.bin/netpgpverify/data/expected17 @@ -0,0 +1,10 @@ +Good signature for a.gpg made Sun Sep 9 17:44:11 2012 +signature 2048/RSA (Encrypt or Sign) 1b68dcfcc0596823 2004-01-12 +fingerprint: d415 9deb 336d e4cc cdfa 00cd 1b68 dcfc c059 6823 +uid Alistair Crooks <agc@alistaircrooks.com> +uid Alistair Crooks <agc@pkgsrc.org> +uid Alistair Crooks <agc@netbsd.org> +uid Alistair Crooks <agc@netflix.com> +encryption 2048/RSA (Encrypt or Sign) 79deb61e488eee74 2004-01-12 +fingerprint: 57c0 c1e6 bf71 8845 416b 9522 79de b61e 488e ee74 + diff --git a/usr.bin/netpgpverify/data/expected18 b/usr.bin/netpgpverify/data/expected18 new file mode 100644 index 000000000000..00bfcb1c193e --- /dev/null +++ b/usr.bin/netpgpverify/data/expected18 @@ -0,0 +1,8 @@ +Good signature for a.gpg made Tue May 31 23:29:10 2016 +signature 2048/RSA (Encrypt or Sign) 1b68dcfcc0596823 2004-01-12 +fingerprint d415 9deb 336d e4cc cdfa 00cd 1b68 dcfc c059 6823 +uid Alistair Crooks <agc@alistaircrooks.com> +uid Alistair Crooks <agc@pkgsrc.org> +uid Alistair Crooks <agc@netbsd.org> +uid Alistair Crooks <agc@netflix.com> + diff --git a/usr.bin/netpgpverify/data/expected19 b/usr.bin/netpgpverify/data/expected19 new file mode 100644 index 000000000000..eb96b974c4cd --- /dev/null +++ b/usr.bin/netpgpverify/data/expected19 @@ -0,0 +1,7 @@ +Good signature for NetBSD-6.0_RC2_hashes.asc made Wed Sep 19 07:53:18 2012 +signature 4096/RSA (Encrypt or Sign) 064973ac4c4a706e 2009-06-23 +fingerprint: ddee 2bdb 9c98 a0d1 d4fb dbf7 0649 73ac 4c4a 706e +uid NetBSD Security Officer <security-officer@NetBSD.org> +encryption 4096/RSA (Encrypt or Sign) 9ff2c24fdf2ce620 2009-06-23 [Expiry 2019-06-21] +fingerprint: 1915 0801 fbd8 f45d 89f2 0205 9ff2 c24f df2c e620 + diff --git a/usr.bin/netpgpverify/data/expected20 b/usr.bin/netpgpverify/data/expected20 new file mode 100644 index 000000000000..4715faa78887 --- /dev/null +++ b/usr.bin/netpgpverify/data/expected20 @@ -0,0 +1,18 @@ +1. tag & 0x3f +2. len + +one pass (tag 4) +======== +b version:3 +b sig type +b hash alg +b pubkey alg +8b keyid + +literal data (tag 11) +============= +b binary/text +b length +c string +L mtime +text diff --git a/usr.bin/netpgpverify/data/expected21 b/usr.bin/netpgpverify/data/expected21 new file mode 100644 index 000000000000..4ae923b07724 --- /dev/null +++ b/usr.bin/netpgpverify/data/expected21 @@ -0,0 +1,8 @@ +Good signature for [stdin] made Tue May 31 23:29:10 2016 +signature 2048/RSA (Encrypt or Sign) 1b68dcfcc0596823 2004-01-12 +fingerprint d415 9deb 336d e4cc cdfa 00cd 1b68 dcfc c059 6823 +uid Alistair Crooks <agc@alistaircrooks.com> +uid Alistair Crooks <agc@pkgsrc.org> +uid Alistair Crooks <agc@netbsd.org> +uid Alistair Crooks <agc@netflix.com> + diff --git a/usr.bin/netpgpverify/data/expected22 b/usr.bin/netpgpverify/data/expected22 new file mode 100644 index 000000000000..e9da07566c77 --- /dev/null +++ b/usr.bin/netpgpverify/data/expected22 @@ -0,0 +1,8 @@ +Good signature for [stdin] made Sun Sep 30 10:50:20 2012 +signature 2048/RSA (Encrypt or Sign) 1b68dcfcc0596823 2004-01-12 +fingerprint d415 9deb 336d e4cc cdfa 00cd 1b68 dcfc c059 6823 +uid Alistair Crooks <agc@alistaircrooks.com> +uid Alistair Crooks <agc@pkgsrc.org> +uid Alistair Crooks <agc@netbsd.org> +uid Alistair Crooks <agc@netflix.com> + diff --git a/usr.bin/netpgpverify/data/expected23 b/usr.bin/netpgpverify/data/expected23 new file mode 100644 index 000000000000..096662a89218 --- /dev/null +++ b/usr.bin/netpgpverify/data/expected23 @@ -0,0 +1,7 @@ +Good signature for [stdin] made Wed Sep 19 07:53:18 2012 +signature 4096/RSA (Encrypt or Sign) 064973ac4c4a706e 2009-06-23 +fingerprint: ddee 2bdb 9c98 a0d1 d4fb dbf7 0649 73ac 4c4a 706e +uid NetBSD Security Officer <security-officer@NetBSD.org> +encryption 4096/RSA (Encrypt or Sign) 9ff2c24fdf2ce620 2009-06-23 [Expiry 2019-06-21] +fingerprint: 1915 0801 fbd8 f45d 89f2 0205 9ff2 c24f df2c e620 + diff --git a/usr.bin/netpgpverify/data/expected24 b/usr.bin/netpgpverify/data/expected24 new file mode 100644 index 000000000000..1e9f824d22c7 --- /dev/null +++ b/usr.bin/netpgpverify/data/expected24 @@ -0,0 +1,8 @@ +Good signature for [stdin] made Mon Sep 10 00:15:38 2012 +signature 2048/RSA (Encrypt or Sign) 1b68dcfcc0596823 2004-01-12 +fingerprint d415 9deb 336d e4cc cdfa 00cd 1b68 dcfc c059 6823 +uid Alistair Crooks <agc@alistaircrooks.com> +uid Alistair Crooks <agc@pkgsrc.org> +uid Alistair Crooks <agc@netbsd.org> +uid Alistair Crooks <agc@netflix.com> + diff --git a/usr.bin/netpgpverify/data/expected25 b/usr.bin/netpgpverify/data/expected25 new file mode 100644 index 000000000000..093d9cf4a0d5 --- /dev/null +++ b/usr.bin/netpgpverify/data/expected25 @@ -0,0 +1,7 @@ +Good signature for NetBSD-6.0_RC1_hashes.gpg made Tue Oct 16 08:12:16 2012 +signature 4096/RSA (Encrypt or Sign) 064973ac4c4a706e 2009-06-23 +fingerprint: ddee 2bdb 9c98 a0d1 d4fb dbf7 0649 73ac 4c4a 706e +uid NetBSD Security Officer <security-officer@NetBSD.org> +encryption 4096/RSA (Encrypt or Sign) 9ff2c24fdf2ce620 2009-06-23 [Expiry 2019-06-21] +fingerprint: 1915 0801 fbd8 f45d 89f2 0205 9ff2 c24f df2c e620 + diff --git a/usr.bin/netpgpverify/data/expected26 b/usr.bin/netpgpverify/data/expected26 new file mode 100644 index 000000000000..a97b231f1c2b --- /dev/null +++ b/usr.bin/netpgpverify/data/expected26 @@ -0,0 +1,7 @@ +Good signature for [stdin] made Tue Oct 16 08:12:16 2012 +signature 4096/RSA (Encrypt or Sign) 064973ac4c4a706e 2009-06-23 +fingerprint: ddee 2bdb 9c98 a0d1 d4fb dbf7 0649 73ac 4c4a 706e +uid NetBSD Security Officer <security-officer@NetBSD.org> +encryption 4096/RSA (Encrypt or Sign) 9ff2c24fdf2ce620 2009-06-23 [Expiry 2019-06-21] +fingerprint: 1915 0801 fbd8 f45d 89f2 0205 9ff2 c24f df2c e620 + diff --git a/usr.bin/netpgpverify/data/expected27 b/usr.bin/netpgpverify/data/expected27 new file mode 100644 index 000000000000..aeee21f0bda9 --- /dev/null +++ b/usr.bin/netpgpverify/data/expected27 @@ -0,0 +1,5 @@ +Good signature for [stdin] made Mon Oct 15 09:28:54 2012 +signature 4096/RSA (Encrypt or Sign) 064973ac4c4a706e 2009-06-23 +fingerprint ddee 2bdb 9c98 a0d1 d4fb dbf7 0649 73ac 4c4a 706e +uid NetBSD Security Officer <security-officer@NetBSD.org> + diff --git a/usr.bin/netpgpverify/data/expected28 b/usr.bin/netpgpverify/data/expected28 new file mode 100644 index 000000000000..e67338d8fe2e --- /dev/null +++ b/usr.bin/netpgpverify/data/expected28 @@ -0,0 +1,5 @@ +Good signature for NetBSD-6.0_hashes.asc made Mon Oct 15 09:28:54 2012 +signature 4096/RSA (Encrypt or Sign) 064973ac4c4a706e 2009-06-23 +fingerprint ddee 2bdb 9c98 a0d1 d4fb dbf7 0649 73ac 4c4a 706e +uid NetBSD Security Officer <security-officer@NetBSD.org> + diff --git a/usr.bin/netpgpverify/data/expected29 b/usr.bin/netpgpverify/data/expected29 new file mode 100644 index 000000000000..8eeb1d6dc8dd --- /dev/null +++ b/usr.bin/netpgpverify/data/expected29 @@ -0,0 +1,7 @@ +Good signature for NetBSD-6.0_RC1_hashes_ascii.gpg made Sun Sep 9 17:41:24 2012 +signature 4096/RSA (Encrypt or Sign) 064973ac4c4a706e 2009-06-23 +fingerprint: ddee 2bdb 9c98 a0d1 d4fb dbf7 0649 73ac 4c4a 706e +uid NetBSD Security Officer <security-officer@NetBSD.org> +encryption 4096/RSA (Encrypt or Sign) 9ff2c24fdf2ce620 2009-06-23 [Expiry 2019-06-21] +fingerprint: 1915 0801 fbd8 f45d 89f2 0205 9ff2 c24f df2c e620 + diff --git a/usr.bin/netpgpverify/data/expected30 b/usr.bin/netpgpverify/data/expected30 new file mode 100644 index 000000000000..d1e6d6df6d68 --- /dev/null +++ b/usr.bin/netpgpverify/data/expected30 @@ -0,0 +1,7 @@ +Good signature for [stdin] made Sun Sep 9 17:41:24 2012 +signature 4096/RSA (Encrypt or Sign) 064973ac4c4a706e 2009-06-23 +fingerprint: ddee 2bdb 9c98 a0d1 d4fb dbf7 0649 73ac 4c4a 706e +uid NetBSD Security Officer <security-officer@NetBSD.org> +encryption 4096/RSA (Encrypt or Sign) 9ff2c24fdf2ce620 2009-06-23 [Expiry 2019-06-21] +fingerprint: 1915 0801 fbd8 f45d 89f2 0205 9ff2 c24f df2c e620 + diff --git a/usr.bin/netpgpverify/data/expected31 b/usr.bin/netpgpverify/data/expected31 new file mode 100644 index 000000000000..1d30ff583935 --- /dev/null +++ b/usr.bin/netpgpverify/data/expected31 @@ -0,0 +1,33 @@ +PROG=p +SRCS=parse.c +WARNS=5 +MKMAN=no +CPPFLAGS+=-g -O0 +LDFLAGS+=-g -O0 + +.include <bsd.prog.mk> + +t: ${PROG} + ./${PROG} gpgsigned-a.gpg +PROG=p +SRCS=parse.c +WARNS=5 +MKMAN=no +CPPFLAGS+=-g -O0 +LDFLAGS+=-g -O0 + +.include <bsd.prog.mk> + +t: ${PROG} + ./${PROG} gpgsigned-a.gpg +PROG=p +SRCS=parse.c +WARNS=5 +MKMAN=no +CPPFLAGS+=-g -O0 +LDFLAGS+=-g -O0 + +.include <bsd.prog.mk> + +t: ${PROG} + ./${PROG} gpgsigned-a.gpg diff --git a/usr.bin/netpgpverify/data/expected32 b/usr.bin/netpgpverify/data/expected32 new file mode 100644 index 000000000000..dadff9f794ca --- /dev/null +++ b/usr.bin/netpgpverify/data/expected32 @@ -0,0 +1,24 @@ +Good signature for b.gpg made Mon Sep 10 00:15:38 2012 +signature 2048/RSA (Encrypt or Sign) 1b68dcfcc0596823 2004-01-12 +fingerprint d415 9deb 336d e4cc cdfa 00cd 1b68 dcfc c059 6823 +uid Alistair Crooks <agc@alistaircrooks.com> +uid Alistair Crooks <agc@pkgsrc.org> +uid Alistair Crooks <agc@netbsd.org> +uid Alistair Crooks <agc@netflix.com> + +Good signature for b.gpg made Mon Sep 10 00:15:38 2012 +signature 2048/RSA (Encrypt or Sign) 1b68dcfcc0596823 2004-01-12 +fingerprint d415 9deb 336d e4cc cdfa 00cd 1b68 dcfc c059 6823 +uid Alistair Crooks <agc@alistaircrooks.com> +uid Alistair Crooks <agc@pkgsrc.org> +uid Alistair Crooks <agc@netbsd.org> +uid Alistair Crooks <agc@netflix.com> + +Good signature for b.gpg made Mon Sep 10 00:15:38 2012 +signature 2048/RSA (Encrypt or Sign) 1b68dcfcc0596823 2004-01-12 +fingerprint d415 9deb 336d e4cc cdfa 00cd 1b68 dcfc c059 6823 +uid Alistair Crooks <agc@alistaircrooks.com> +uid Alistair Crooks <agc@pkgsrc.org> +uid Alistair Crooks <agc@netbsd.org> +uid Alistair Crooks <agc@netflix.com> + diff --git a/usr.bin/netpgpverify/data/expected33 b/usr.bin/netpgpverify/data/expected33 new file mode 100644 index 000000000000..1e078bb06e73 --- /dev/null +++ b/usr.bin/netpgpverify/data/expected33 @@ -0,0 +1,40 @@ +PROG=p +SRCS=parse.c +WARNS=5 +MKMAN=no +CPPFLAGS+=-g -O0 +LDFLAGS+=-g -O0 + +.include <bsd.prog.mk> + +t: ${PROG} + ./${PROG} gpgsigned-a.gpg +1. tag & 0x3f +2. len + +one pass (tag 4) +======== +b version:3 +b sig type +b hash alg +b pubkey alg +8b keyid + +literal data (tag 11) +============= +b binary/text +b length +c string +L mtime +text +PROG=p +SRCS=parse.c +WARNS=5 +MKMAN=no +CPPFLAGS+=-g -O0 +LDFLAGS+=-g -O0 + +.include <bsd.prog.mk> + +t: ${PROG} + ./${PROG} gpgsigned-a.gpg diff --git a/usr.bin/netpgpverify/data/expected34 b/usr.bin/netpgpverify/data/expected34 new file mode 100644 index 000000000000..27a6592c3122 --- /dev/null +++ b/usr.bin/netpgpverify/data/expected34 @@ -0,0 +1,8 @@ +Good signature for det.sig made Thu Oct 18 02:12:33 2012 +signature 2048/RSA (Encrypt or Sign) 1b68dcfcc0596823 2004-01-12 +fingerprint d415 9deb 336d e4cc cdfa 00cd 1b68 dcfc c059 6823 +uid Alistair Crooks <agc@alistaircrooks.com> +uid Alistair Crooks <agc@pkgsrc.org> +uid Alistair Crooks <agc@netbsd.org> +uid Alistair Crooks <agc@netflix.com> + diff --git a/usr.bin/netpgpverify/data/expected35 b/usr.bin/netpgpverify/data/expected35 new file mode 100644 index 000000000000..04dc803533a2 --- /dev/null +++ b/usr.bin/netpgpverify/data/expected35 @@ -0,0 +1,16 @@ +To Do +===== +tests with -k sig +detached sigs +DSA + +Done +==== +basics +localise pgp_read_packets +fix lint +WARNS=5 +lib man page +prog man page +do we do it statically linked as well? +multiple files in netpgpverify diff --git a/usr.bin/netpgpverify/data/expected36 b/usr.bin/netpgpverify/data/expected36 new file mode 100644 index 000000000000..6ea2a3d30d68 --- /dev/null +++ b/usr.bin/netpgpverify/data/expected36 @@ -0,0 +1,5 @@ +Good signature for in1.gpg made Mon Oct 22 04:45:41 2012 +signature 2048/DSA 263fe78562e2fc7e 2012-10-21 +fingerprint d2e5 07b6 5d59 33d3 9c8d a618 263f e785 62e2 fc7e +uid David Armstrong (Test DSA key - do not use) <dsa@dsa.com> + diff --git a/usr.bin/netpgpverify/data/expected37 b/usr.bin/netpgpverify/data/expected37 new file mode 100644 index 000000000000..1e6162a68e35 --- /dev/null +++ b/usr.bin/netpgpverify/data/expected37 @@ -0,0 +1,5 @@ +Good signature for [stdin] made Mon Oct 22 04:45:41 2012 +signature 2048/DSA 263fe78562e2fc7e 2012-10-21 +fingerprint d2e5 07b6 5d59 33d3 9c8d a618 263f e785 62e2 fc7e +uid David Armstrong (Test DSA key - do not use) <dsa@dsa.com> + diff --git a/usr.bin/netpgpverify/data/expected38 b/usr.bin/netpgpverify/data/expected38 new file mode 100644 index 000000000000..65f8b1fc90df --- /dev/null +++ b/usr.bin/netpgpverify/data/expected38 @@ -0,0 +1,5 @@ +Good signature for in1.asc made Mon Oct 22 04:45:26 2012 +signature 2048/DSA 263fe78562e2fc7e 2012-10-21 +fingerprint d2e5 07b6 5d59 33d3 9c8d a618 263f e785 62e2 fc7e +uid David Armstrong (Test DSA key - do not use) <dsa@dsa.com> + diff --git a/usr.bin/netpgpverify/data/expected39 b/usr.bin/netpgpverify/data/expected39 new file mode 100644 index 000000000000..b6d57029d3cf --- /dev/null +++ b/usr.bin/netpgpverify/data/expected39 @@ -0,0 +1,5 @@ +Good signature for [stdin] made Mon Oct 22 04:45:26 2012 +signature 2048/DSA 263fe78562e2fc7e 2012-10-21 +fingerprint d2e5 07b6 5d59 33d3 9c8d a618 263f e785 62e2 fc7e +uid David Armstrong (Test DSA key - do not use) <dsa@dsa.com> + diff --git a/usr.bin/netpgpverify/data/expected40 b/usr.bin/netpgpverify/data/expected40 new file mode 100644 index 000000000000..a4bda3c562f9 --- /dev/null +++ b/usr.bin/netpgpverify/data/expected40 @@ -0,0 +1,6 @@ +# .NetBSD: Makefile,v 1.5.10.1 2012/05/06 18:14:16 agc Exp . + +SUBDIR+= lib .WAIT +SUBDIR+= bin + +.include <bsd.subdir.mk> diff --git a/usr.bin/netpgpverify/data/expected41 b/usr.bin/netpgpverify/data/expected41 new file mode 100644 index 000000000000..a4bda3c562f9 --- /dev/null +++ b/usr.bin/netpgpverify/data/expected41 @@ -0,0 +1,6 @@ +# .NetBSD: Makefile,v 1.5.10.1 2012/05/06 18:14:16 agc Exp . + +SUBDIR+= lib .WAIT +SUBDIR+= bin + +.include <bsd.subdir.mk> diff --git a/usr.bin/netpgpverify/data/expected42 b/usr.bin/netpgpverify/data/expected42 new file mode 100644 index 000000000000..a4bda3c562f9 --- /dev/null +++ b/usr.bin/netpgpverify/data/expected42 @@ -0,0 +1,6 @@ +# .NetBSD: Makefile,v 1.5.10.1 2012/05/06 18:14:16 agc Exp . + +SUBDIR+= lib .WAIT +SUBDIR+= bin + +.include <bsd.subdir.mk> diff --git a/usr.bin/netpgpverify/data/expected43 b/usr.bin/netpgpverify/data/expected43 new file mode 100644 index 000000000000..a4bda3c562f9 --- /dev/null +++ b/usr.bin/netpgpverify/data/expected43 @@ -0,0 +1,6 @@ +# .NetBSD: Makefile,v 1.5.10.1 2012/05/06 18:14:16 agc Exp . + +SUBDIR+= lib .WAIT +SUBDIR+= bin + +.include <bsd.subdir.mk> diff --git a/usr.bin/netpgpverify/data/expected44 b/usr.bin/netpgpverify/data/expected44 new file mode 100644 index 000000000000..a8786ee113c9 --- /dev/null +++ b/usr.bin/netpgpverify/data/expected44 @@ -0,0 +1,5 @@ +Good signature for in2.gpg made Mon Oct 22 06:24:09 2012 +signature 2048/DSA 263fe78562e2fc7e 2012-10-21 +fingerprint d2e5 07b6 5d59 33d3 9c8d a618 263f e785 62e2 fc7e +uid David Armstrong (Test DSA key - do not use) <dsa@dsa.com> + diff --git a/usr.bin/netpgpverify/data/expected45 b/usr.bin/netpgpverify/data/expected45 new file mode 100644 index 000000000000..379ffce293e8 --- /dev/null +++ b/usr.bin/netpgpverify/data/expected45 @@ -0,0 +1,5 @@ +Good signature for in2.asc made Mon Oct 22 06:24:26 2012 +signature 2048/DSA 263fe78562e2fc7e 2012-10-21 +fingerprint d2e5 07b6 5d59 33d3 9c8d a618 263f e785 62e2 fc7e +uid David Armstrong (Test DSA key - do not use) <dsa@dsa.com> + diff --git a/usr.bin/netpgpverify/data/expected46 b/usr.bin/netpgpverify/data/expected46 new file mode 100644 index 000000000000..4c262d05b98e --- /dev/null +++ b/usr.bin/netpgpverify/data/expected46 @@ -0,0 +1,8 @@ +Ignoring unusual/reserved signature subpacket 18 +Good signature for NetBSD-6.0_hashes.asc made Mon Oct 15 09:28:54 2012 +signature 4096/RSA (Encrypt or Sign) 064973ac4c4a706e 2009-06-23 +fingerprint: ddee 2bdb 9c98 a0d1 d4fb dbf7 0649 73ac 4c4a 706e +uid NetBSD Security Officer <security-officer@NetBSD.org> +encryption 4096/RSA (Encrypt or Sign) 9ff2c24fdf2ce620 2009-06-23 [Expiry 2019-06-21] +fingerprint: 1915 0801 fbd8 f45d 89f2 0205 9ff2 c24f df2c e620 + diff --git a/usr.bin/netpgpverify/data/in1.asc b/usr.bin/netpgpverify/data/in1.asc new file mode 100644 index 000000000000..d2b79f60f77d --- /dev/null +++ b/usr.bin/netpgpverify/data/in1.asc @@ -0,0 +1,16 @@ +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA256 + +# .NetBSD: Makefile,v 1.5.10.1 2012/05/06 18:14:16 agc Exp . + +SUBDIR+= lib .WAIT +SUBDIR+= bin + +.include <bsd.subdir.mk> +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.4.11 (NetBSD) + +iF4EAREIAAYFAlCFMdYACgkQJj/nhWLi/H7CkQEAgDQrFwPD76JC+6FnOKEz/9DP +H7WjRRMoIQNTGC3ZXRsA/1xah8eFePQDmTO1sQGnINbgX9vZ7GAFOgTjW7+tVb7H +=wtKb +-----END PGP SIGNATURE----- diff --git a/usr.bin/netpgpverify/data/in1.gpg b/usr.bin/netpgpverify/data/in1.gpg Binary files differnew file mode 100644 index 000000000000..3e96e861ff56 --- /dev/null +++ b/usr.bin/netpgpverify/data/in1.gpg diff --git a/usr.bin/netpgpverify/data/in2.asc b/usr.bin/netpgpverify/data/in2.asc new file mode 100644 index 000000000000..aaf8e119456c --- /dev/null +++ b/usr.bin/netpgpverify/data/in2.asc @@ -0,0 +1,16 @@ +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA256 + +# .NetBSD: Makefile,v 1.5.10.1 2012/05/06 18:14:16 agc Exp . + +SUBDIR+= lib .WAIT +SUBDIR+= bin + +.include <bsd.subdir.mk> +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.4.11 (NetBSD) + +iF4EAREIAAYFAlCFSQoACgkQJj/nhWLi/H6aKAD9HCLTwY8CwiqTXrzKxHZ5lHQn +qEZbcbXjkCxlk+m/PHUA/2Whlc0t5ZtmI221LQy5inTnzpu1U75E5lJvw0YMTdXJ +=v788 +-----END PGP SIGNATURE----- diff --git a/usr.bin/netpgpverify/data/in2.gpg b/usr.bin/netpgpverify/data/in2.gpg Binary files differnew file mode 100644 index 000000000000..83a7dfbe61fc --- /dev/null +++ b/usr.bin/netpgpverify/data/in2.gpg diff --git a/usr.bin/netpgpverify/data/jj.asc b/usr.bin/netpgpverify/data/jj.asc new file mode 100644 index 000000000000..65661d69f8db --- /dev/null +++ b/usr.bin/netpgpverify/data/jj.asc @@ -0,0 +1,32 @@ +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA1 + +1. tag & 0x3f +2. len + +one pass (tag 4) +======== +b version:3 +b sig type +b hash alg +b pubkey alg +8b keyid + +literal data (tag 11) +============= +b binary/text +b length +c string +L mtime +text +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.4.11 (NetBSD) + +iQEcBAEBAgAGBQJQaIZcAAoJEBto3PzAWWgj678IALbDHon3Rm6qUhn7k1TFT6D3 +yi/jzf3piSJGsgUg2wEghs175edC/cJK3lG9Gx/3/uQq06R9g37nVRX8I0sK7yT2 +XgR+RHoGh/b+CQxdRNC+ub5QoNb8LcmCb/MQGq2KK9otSExiy4WMUP4K1DblaK5L ++Hg4VTooMot1NVqyFSoB2aZauXc2F4ZVh5q0fn8w5GEw45P+AUUbmzpgbLwXbl+I +tMsX54V1dxyDcCYUs0xUH/VxJUQEeIlDbCOXYMbCVtggYRqKksTr+u/riw/Llnql +jQdq5rBRW1SlD7Ll6z/LF2WBJOWtHzp4qbnBGSq5uB1q37H3mWL28f1tL//TUjM= +=EX8W +-----END PGP SIGNATURE----- diff --git a/usr.bin/netpgpverify/data/message b/usr.bin/netpgpverify/data/message new file mode 100644 index 000000000000..08844f75c649 --- /dev/null +++ b/usr.bin/netpgpverify/data/message @@ -0,0 +1 @@ +This is an example messsage. diff --git a/usr.bin/netpgpverify/data/message.keyring b/usr.bin/netpgpverify/data/message.keyring Binary files differnew file mode 100644 index 000000000000..2ae71b9e2d7f --- /dev/null +++ b/usr.bin/netpgpverify/data/message.keyring diff --git a/usr.bin/netpgpverify/data/message.v1.asc b/usr.bin/netpgpverify/data/message.v1.asc new file mode 100644 index 000000000000..238ee4df345b --- /dev/null +++ b/usr.bin/netpgpverify/data/message.v1.asc @@ -0,0 +1,14 @@ +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA1 + +This is an example messsage. +-----BEGIN PGP SIGNATURE----- + +iQEcBAEBAgAGBQJpe96fAAoJEIGRNTbVsiooKJAIAI7DdO0v1pqIF/EdCELBLmSk +BlKFeKIl2k5GEh6Z6LUHebiJd1GfpNN7Pf99oqyRm9dg3bDdfZ6BdJkiEJtEQ8kz +PXqoMhdSQ9rtmYxyZBMYVcGFFizl/mpXupwi9Rq7hRogr7NDLaJVFwwDrGrx5mSU +A2pKAeejB0F5l/rbpfzErqnajBeCZmzjCkPlgfKGMSSiVONC2rxTYyJUa6pSLruq +jrfgfsmDk6TLKXA8xNchCyMJoIs3Drtq7XeY9Y7FFPEY9hFH8+YYZmElaK8XOzYy +tLeMCwCdLMwL7mmS2rFAg4U60zIYUzWI1nWBaHBVlv50mtTuiNN83/axIpoI3dE= +=cW1k +-----END PGP SIGNATURE----- diff --git a/usr.bin/netpgpverify/data/message.v1.asc.expected b/usr.bin/netpgpverify/data/message.v1.asc.expected new file mode 100644 index 000000000000..14e76b1ced74 --- /dev/null +++ b/usr.bin/netpgpverify/data/message.v1.asc.expected @@ -0,0 +1,5 @@ +Good signature for message.v1.asc made Thu Jan 29 23:26:39 2026 +signature 2048/RSA (Encrypt or Sign) 81913536d5b22a28 2026-01-29 +fingerprint 5bc4 b091 22be 606e d732 8a08 8191 3536 d5b2 2a28 +uid Test Key <test@example.com> + diff --git a/usr.bin/netpgpverify/data/message.v1.sig b/usr.bin/netpgpverify/data/message.v1.sig Binary files differnew file mode 100644 index 000000000000..c2bc90f3d971 --- /dev/null +++ b/usr.bin/netpgpverify/data/message.v1.sig diff --git a/usr.bin/netpgpverify/data/message.v1.sig.expected b/usr.bin/netpgpverify/data/message.v1.sig.expected new file mode 100644 index 000000000000..362d5f2aaa31 --- /dev/null +++ b/usr.bin/netpgpverify/data/message.v1.sig.expected @@ -0,0 +1,5 @@ +Good signature for message.v1.sig made Thu Jan 29 23:26:23 2026 +signature 2048/RSA (Encrypt or Sign) 81913536d5b22a28 2026-01-29 +fingerprint 5bc4 b091 22be 606e d732 8a08 8191 3536 d5b2 2a28 +uid Test Key <test@example.com> + diff --git a/usr.bin/netpgpverify/data/message.v2.asc b/usr.bin/netpgpverify/data/message.v2.asc new file mode 100644 index 000000000000..abff22db4e15 --- /dev/null +++ b/usr.bin/netpgpverify/data/message.v2.asc @@ -0,0 +1,15 @@ +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA256 + +This is an example messsage. +-----BEGIN PGP SIGNATURE----- + +iQEzBAEBCAAdFiEEW8SwkSK+YG7XMooIgZE1NtWyKigFAml730EACgkQgZE1NtWy +KijBCwf/aMxfreT1hNjzwfE9cHFVgjfI+P0pzuf4HVM6Xv3niQAV6Kn8hIn4hlS2 +oyo1aKoqek8EKKBHXWi6oTQ3AjfsJDzte2axE2w1TKCRQucSL7kaJAFpHmTM0gr6 +nQsoba1aFuxIa9ENRs5SsW47IdR5gFTg9QXdX2LepGFHDk9kULOy90xt2aHXpdft +COvz/9KTok97gi+Tc0YsF+IExIQe0/LkadziKVI3GwyEgksaJw6h7aCF5YxA6N5c +R6jgGmBtKzjeDb8IbFH+IRuBZGzt2r7a3CiScgOjm1T3Z/kVETBor7nBYCcb5S6q +dIZlIMOdempGnvznuzBJGZBWLECMxQ== +=5+xC +-----END PGP SIGNATURE----- diff --git a/usr.bin/netpgpverify/data/message.v2.asc.expected b/usr.bin/netpgpverify/data/message.v2.asc.expected new file mode 100644 index 000000000000..358f71d49ae9 --- /dev/null +++ b/usr.bin/netpgpverify/data/message.v2.asc.expected @@ -0,0 +1,5 @@ +Good signature for message.v2.asc made Thu Jan 29 23:29:21 2026 +signature 2048/RSA (Encrypt or Sign) 81913536d5b22a28 2026-01-29 +fingerprint 5bc4 b091 22be 606e d732 8a08 8191 3536 d5b2 2a28 +uid Test Key <test@example.com> + diff --git a/usr.bin/netpgpverify/data/message.v2.sig b/usr.bin/netpgpverify/data/message.v2.sig Binary files differnew file mode 100644 index 000000000000..09cf3957d628 --- /dev/null +++ b/usr.bin/netpgpverify/data/message.v2.sig diff --git a/usr.bin/netpgpverify/data/message.v2.sig.expected b/usr.bin/netpgpverify/data/message.v2.sig.expected new file mode 100644 index 000000000000..0baf1a35684f --- /dev/null +++ b/usr.bin/netpgpverify/data/message.v2.sig.expected @@ -0,0 +1,5 @@ +Good signature for message.v2.sig made Thu Jan 29 23:29:14 2026 +signature 2048/RSA (Encrypt or Sign) 81913536d5b22a28 2026-01-29 +fingerprint 5bc4 b091 22be 606e d732 8a08 8191 3536 d5b2 2a28 +uid Test Key <test@example.com> + diff --git a/usr.bin/netpgpverify/data/pubring.gpg b/usr.bin/netpgpverify/data/pubring.gpg Binary files differnew file mode 100644 index 000000000000..796a40a1398a --- /dev/null +++ b/usr.bin/netpgpverify/data/pubring.gpg diff --git a/usr.bin/shmif_pcapin/Makefile b/usr.bin/shmif_pcapin/Makefile new file mode 100644 index 000000000000..30a9f8347f72 --- /dev/null +++ b/usr.bin/shmif_pcapin/Makefile @@ -0,0 +1,11 @@ +.include <bsd.own.mk> + +TESTSDIR= ${TESTSBASE}/usr.bin/shmif_pcapin +FILESDIR= ${TESTSDIR} + +TESTS_SH+= t_basic +TESTS_SH_SRC_t_basic= ../../net/net_common.sh t_basic.sh + +FILES+= d_pcap.in.bz2.uue d_pcap.out.bz2.uue + +.include <bsd.test.mk> diff --git a/usr.bin/shmif_pcapin/d_pcap.in.bz2.uue b/usr.bin/shmif_pcapin/d_pcap.in.bz2.uue new file mode 100644 index 000000000000..f7bebd31beb4 --- /dev/null +++ b/usr.bin/shmif_pcapin/d_pcap.in.bz2.uue @@ -0,0 +1,27 @@ +begin 644 d_pcap.in.bz2 +M0EIH.3%!6293671X8T@`",M_______TOA>KK]E_____W_____^\C:_:XZKOZ +M]#3:(5__T`/^`.@`&YM"%4,@-`!DQJ````T9&@``````T-!DT`&@```````` +M`:`/*%*@]1^GJHT`!ZAM(```#0T```:`!H:``&@````````````#1"?_ZJJ8 +MF`F```````!,``````````$R8````````$PFF(`T#30:#$R`&AD&C`(`#31D +M!A`9,@R:9-#$9,@-``:,@8F3(```#0`"HI(HU-I)Z0]0]1Z@`&F@:``-H@TR +M#:0\I_ZJ@]1I@@/4:,1ZAM33:FAIM3)ZCU-&F)^IFE/4\D:-E!Z@T:-J;-SK +MR`JJ%4J5)T*)-32B3R*)+)(CJ$2:E1)B(DZE826U/9(DPB3#@JQ9*B2PSSSS +M9LVP9M5FS9LV;-FS9LV;-FS9LV;-FS9YY^B\\0\^J17N5=!4RI/5U,(DK%&* +M+4Q6)$F+99227:0M%1)4F*+2]"26DF2),B\_$F%B2IHRPQ<&+5MEM7SBR),+ +M5NA$EP56V8PDD<U$E)I5'IE.XK)2KZVOS,FEDU^3H9-##$KC#IC=6T`````` +M`````````$!`^\_VJ&P;!ZKK/X\O9-8[E>O%K^>4,BKE+2UEE#G&E557XWT6 +M3)?&:'#=Z_8XKD/#<ISSQ7-=VYYWS6>=<=X3R;:N`W+<OE/FN&[MK/DNM:K5 +M5:B37(DK%Y:L63LU<^WK#KEAW"S0K;L&)$F_]WVR)-HB31I%Y*Z_'P[K:\!$ +MF6Q6N(B3'5:O3LMHB39(DP23<+QU<XI5B#=[S`R4V:)+.3X6#M>!@X2)+/;J +MU(2I$E@62254G\/$Y<AH=2T]`^6^\W3K42:>P?68W+;-5NVC?]BKLE>D1)[! +MAIV+L63:-'9,F.S=SP=#1O&'LU;Y7VE;5]MAL?N,,>Q8=$KE-&_9/NJR[5AT +M:OGJ<Q6[5-A3?.Z='X&@\TYB1NVX=XZIJ.*X;P'>O>NL=>UG?N*_6UW1/!<1 +MQ&V<1X+7<5Q7Q&NZMWW?]LUG\G&>&^DU72O+N4YCO'':6\=HWSKF]=H_JUVT +M8;IXC8."T.1QMN^1^'IG^6R;C>OZ$2<)>2[!I=6\JB2(!0'LHS1`1*+YBP:G +M<^L*HT2-$4:2-E635)24E@E*SFA]Z1`1.%C!!DXL&*2VN*BL9^L*\M)6`ZE7 +M35\PZ>-(A%.BD$,U)2TG'S,O.%EED(0A"(HOTT<OU]O?XC?D```````HI]&B +MI4911111B@:(7\)-.;XQ#&>&(8]>)+$G;[YCYC+M_H;?9NHB5R&HPYOI]5HZ +M>OIO&8((JP?0=@*@/^`GMR#G\",%>3">$0!3L@_2.$DN8QPFL,L#<G,@M@,: +J-JKQW2,:6F)XLZ5PWCHDXS0;&N$ITBCG5:$2?OYN3_XNY(IPH2#H\,:0 +` +end diff --git a/usr.bin/shmif_pcapin/d_pcap.out.bz2.uue b/usr.bin/shmif_pcapin/d_pcap.out.bz2.uue new file mode 100644 index 000000000000..616bf2369559 --- /dev/null +++ b/usr.bin/shmif_pcapin/d_pcap.out.bz2.uue @@ -0,0 +1,13 @@ +begin 644 d_pcap.out.bz2 +M0EIH.3%!62936>CJBS$`#$]?@``00&5_\0@B0``_Y?]@0`*8VP``<_2/4T_U +M4!,``0P1AS_]50(9#31D9&1H9,@)JDDTF*>13U/4&0>IFB:;:H8`9--!D,$- +M,1HQTI'UI>:/S1B,1J3^)&3UD9,D=9'Y(_1'A(_J1RD?*1Y5(]I&2/&1SD<D +M<T??OF9F````````".THE5<[;+;H6@P`!555408@``-!@!SY[[[[[[\_C(\) +M'"D<Y&J1D)=NFVM:^5(Q&D>$C$:1WD<9'K2/YD<N/'-:RY2,KQD95JD9(=9& +M^M]9K4C:D:N$C*OWD962,K_*1OQVUK761DC>1VD=Y''COK6MY'G(VD<,X:UK +MVD;R.'#AK6M4C)&I&LUK6MI&U(R1FVV:UY2.TCTD>,C4C?>S)'61QD;2,D=) +M'I(X2/A(X2.E([2.5(^<C*1\Y'TD;2/*D?1&Z,1B/61]I'_2-I'WI'X1[R,1 +M]I'=&\CI(])'>D>T)>\C>$O@CM2.<CZR-4CA(R1DC$=4=Z1J1VD>Z/Q(^,CS +.1VD?^+N2*<*$AT=468@C +` +end diff --git a/usr.bin/shmif_pcapin/t_basic.sh b/usr.bin/shmif_pcapin/t_basic.sh new file mode 100644 index 000000000000..ef364878e4bd --- /dev/null +++ b/usr.bin/shmif_pcapin/t_basic.sh @@ -0,0 +1,89 @@ +# $NetBSD: t_basic.sh,v 1.1 2024/09/02 05:16:37 ozaki-r Exp $ +# +# Copyright (c) 2017-2018 Internet Initiative Japan Inc. +# Copyright (c) 2011 The NetBSD Foundation, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +SOCK=unix://commsock +BUS=bus0 + +unpack_file() +{ + + atf_check -s exit:0 uudecode $(atf_get_srcdir)/${1}.bz2.uue + atf_check -s exit:0 bunzip2 -f ${1}.bz2 +} + +atf_test_case pcap cleanup + +pcap_head() +{ + + atf_set "descr" "Write frames from pcap(3) file to shmif(4) interface" +} + +pcap_body() +{ + unpack_file d_pcap.in + unpack_file d_pcap.out + + rump_server_npf_start ${SOCK} # need librumpdev_bpf + rump_server_add_iface ${SOCK} shmif0 ${BUS} + + export RUMP_SERVER=${SOCK} + export LD_PRELOAD=/usr/lib/librumphijack.so + export RUMPHIJACK=path=/rump,socket=all:nolocal,sysctl=yes,,blanket=/dev/bpf + + atf_check -s exit:0 rump.ifconfig shmif0 up + + # Capture frames on shmif0 to examine later. + tcpdump -c 58 -eni shmif0 -w shmif0.in.pcap & + sleep 1 # give shmif0 a change to turn into promiscuous mode + # Write frames to the bus. + atf_check -s exit:0 -o ignore shmif_pcapin d_pcap.in ${BUS} + wait # for tcpdump to exit + + # Check if written frames surely arrives at shmif0. + atf_check -s exit:0 -o match:"input: 58 packets, 5684 bytes" rump.ifconfig -v shmif0 + # Check if frames captured on shmif0 are expected ones. + atf_check -s exit:0 -o file:d_pcap.out -e ignore tcpdump -entr shmif0.in.pcap + + unset LD_PRELOAD + unset RUMP_SERVER +} + +pcap_cleanup() +{ + + $DEBUG && dump + cleanup +} + + +atf_init_test_cases() +{ + + atf_add_test_case pcap +} diff --git a/usr.bin/stat/Makefile b/usr.bin/stat/Makefile new file mode 100644 index 000000000000..9118b2434b8f --- /dev/null +++ b/usr.bin/stat/Makefile @@ -0,0 +1,7 @@ +# $NetBSD: Makefile,v 1.1 2024/03/14 21:00:33 rillig Exp $ + +TESTSDIR= ${TESTSBASE}/usr.bin/stat + +TESTS_SH= t_stat + +.include <bsd.test.mk> diff --git a/usr.bin/stat/t_stat.sh b/usr.bin/stat/t_stat.sh new file mode 100644 index 000000000000..b4bc56320d18 --- /dev/null +++ b/usr.bin/stat/t_stat.sh @@ -0,0 +1,68 @@ +# $NetBSD: t_stat.sh,v 1.2 2024/03/14 21:17:54 rillig Exp $ +# +# Copyright (c) 2024 The NetBSD Foundation, Inc. +# All rights reserved. +# +# This code is derived from software contributed to The NetBSD Foundation +# by Roland Illig. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +atf_test_case string_format +string_format_head() { + atf_set "descr" "Tests the string output format 'S'" +} +string_format_body() { + echo 'äöü' > './Ümläute' + + atf_check -o 'inline:plain <Ümläute>\n' \ + stat -f 'plain <%SN>' 'Ümläute' + + atf_check -o 'inline:right-aligned < Ümläute>\n' \ + stat -f 'right-aligned <%20SN>' 'Ümläute' + + atf_check -o 'inline:left-aligned <Ümläute >\n' \ + stat -f 'left-aligned <%-20SN>' 'Ümläute' + + atf_check -s exit:1 -o ignore -e 'inline:stat: % SN: bad format\n' \ + stat -f 'string-space <% SN>' 'Ümläute' + + atf_check -s exit:1 -o ignore -e 'inline:stat: %+SN: bad format\n' \ + stat -f 'string-plus <%+SN>' 'Ümläute' + + atf_check -s exit:1 -o ignore -e 'inline:stat: %0SN: bad format\n' \ + stat -f 'string-zero <%0SN>' 'Ümläute' + + atf_check -o 'inline:vis <\303\234ml\303\244ute>\n' \ + stat -f 'vis <%#SN>' 'Ümläute' + + atf_check -o 'inline:vis left-aligned <\303\234ml\303\244ute >\n' \ + stat -f 'vis left-aligned <%#-30SN>' 'Ümläute' + + atf_check -o 'inline:vis right-aligned < \303\234ml\303\244ute>\n' \ + stat -f 'vis right-aligned <%#30SN>' 'Ümläute' +} + +atf_init_test_cases() { + atf_add_test_case string_format +} diff --git a/usr.bin/xlint/lint1/expr.c b/usr.bin/xlint/lint1/expr.c new file mode 100644 index 000000000000..77f64ffd00ba --- /dev/null +++ b/usr.bin/xlint/lint1/expr.c @@ -0,0 +1,33 @@ +/* $NetBSD: expr.c,v 1.1 2024/06/08 09:09:20 rillig Exp $ */ +# 3 "expr.c" + +/* + * Miscellaneous tests for expressions. + */ + +/* lint1-extra-flags: -X 351 */ + +struct bit_fields { + unsigned u32: 32; +}; + +unsigned long +expr_cond_cvt(unsigned long ul) +{ + struct bit_fields bits = { 0 }; + // Combining 'unsigned:32' and 'unsigned long' in the ':' operator + // results in 'unsigned long'. + return bits.u32 < ul ? bits.u32 : ul; +} + +// Before tree.c 1.76 from 2014-04-17, lint crashed with an internal error, +// due to an uninitialized right operand of a tree node. +void +crash_in_assignment(void) +{ + /* expect+1: warning: 'x' set but not used in function 'crash_in_assignment' [191] */ + double x = 1; + int foo = 0; + if (foo) + x = 1; +} diff --git a/usr.bin/xlint/lint1/gcc.c b/usr.bin/xlint/lint1/gcc.c new file mode 100644 index 000000000000..a239bfd83220 --- /dev/null +++ b/usr.bin/xlint/lint1/gcc.c @@ -0,0 +1,130 @@ +/* $NetBSD: gcc.c,v 1.7 2026/01/20 23:46:36 rillig Exp $ */ +# 3 "gcc.c" + +/* + * Miscellaneous tests that are specific to lint's GCC mode. + */ + +/* lint1-extra-flags: -chaapbrz -X 351 */ + +// Before C99 introduced __func__, GCC already had __FUNCTION__ with the same +// semantics. +const char * +gcc_function(void) +{ + /* expect+1: error: negative array dimension (-13) [20] */ + typedef int size[-(int)sizeof __FUNCTION__]; + + return __FUNCTION__; +} + +// Before C99 introduced designators in initializers, GCC already had them, +// although with a different syntax for struct/union members and with the +// a...b for ranges of array elements. +int array_range_initializers[256] = { + [2] = 1, + [3] = 2, + [4 ... 5] = 3 +}; + +_Bool dbl_isinf(double); + +// Test that the GCC '__extension__' and '__typeof' are recognized. +void +extension_and_typeof(void) +{ + double __logbw = 1; + if (__extension__(({ + __typeof((__logbw)) x_ = (__logbw); + !dbl_isinf((x_)); + }))) + __logbw = 1; +} + +int +range_in_case_label(int i) +{ + switch (i) { + case 1 ... 40: // This is a GCC extension. + return 1; + default: + return 2; + } +} + +union { + int i; + char *s; +} initialize_union_with_mixed_designators[] = { + { i: 1 }, /* GCC-style */ + { s: "foo" }, /* GCC-style */ + { .i = 1 }, /* C99-style */ + { .s = "foo" } /* C99-style */ +}; + +union { + int i[10]; + short s; +} initialize_union_with_gcc_designators[] = { + { s: 2 }, + { i: { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } }, +}; + +void +declaration_of_variable_array(int i) +{ + int array[i]; + while (i-- > 0) + array[i] = 0; +} + +/* + * Before cgram.y 1.226 from 2021-05-03, lint could not parse typeof(...) if + * there was a statement before it. + */ +void * +typeof_after_statement(void **ptr) +{ + return ({ + if (*ptr != (void *)0) + ptr++; + __typeof__(*ptr) ret = *ptr; + ret; + }); +} + +const char * +auto_type(const char *ptr) +{ + __auto_type pp = &ptr; + return *pp; +} + +void +atomic_functions(void) +{ + static unsigned long long v, *pv; + v = __atomic_load_n(pv, 0); + v = __atomic_exchange_n(pv, 0, 0); + v = __atomic_add_fetch(pv, 0, 0); + v = __atomic_sub_fetch(pv, 0, 0); + v = __atomic_and_fetch(pv, 0, 0); + v = __atomic_xor_fetch(pv, 0, 0); + v = __atomic_or_fetch(pv, 0, 0); + v = __atomic_nand_fetch(pv, 0, 0); + v = __atomic_fetch_add(pv, 0, 0); + v = __atomic_fetch_sub(pv, 0, 0); + v = __atomic_fetch_and(pv, 0, 0); + v = __atomic_fetch_xor(pv, 0, 0); + v = __atomic_fetch_or(pv, 0, 0); + v = __atomic_fetch_nand(pv, 0, 0); + + static char c, *pc; + c = __atomic_load_n(pc, 0); + c = __atomic_exchange_n(pc, 0, 0); + + /* expect+1: warning: conversion from 'unsigned long long' to 'char' may lose accuracy [132] */ + c = __atomic_exchange_n(pv, 0, 0); +} + +__float128 f128 = 0.0; diff --git a/usr.bin/xlint/lint1/init_c99.c b/usr.bin/xlint/lint1/init_c99.c new file mode 100644 index 000000000000..a9a72552bba2 --- /dev/null +++ b/usr.bin/xlint/lint1/init_c99.c @@ -0,0 +1,739 @@ +/* $NetBSD: init_c99.c,v 1.5 2025/04/12 15:49:50 rillig Exp $ */ +# 3 "init_c99.c" + +// Tests for initialization in C99 or later, mainly for designators. +// +// See C99 6.7.8 "Initialization". + +/* lint1-flags: -Sw -X 351 */ + +void use(const void *); + +typedef struct any { + const void *value; +} any; + + +// C99 6.7.8p11 says "optionally enclosed in braces". Whether this wording +// means "a single pair of braces" or "as many pairs of braces as you want" +// is left for interpretation to the reader. +int scalar_without_braces = 3; +int scalar_with_optional_braces = { 3 }; +int scalar_with_too_many_braces = {{ 3 }}; +/* expect+1: error: too many initializers for 'int' [174] */ +int scalar_with_too_many_initializers = { 3, 5 }; + + +// See initialization_expr, 'handing over to INIT'. +void +struct_initialization_via_assignment(any arg) +{ + any local = arg; + use(&local); +} + + +// See initialization_expr, initialization_init_array_from_string. +char static_duration[] = "static duration"; +signed char static_duration_signed[] = "static duration"; +unsigned char static_duration_unsigned[] = "static duration"; +int static_duration_wchar[] = L"static duration"; + +// See init_expr. +void +initialization_by_braced_string(void) +{ + any local = { "hello" }; + use(&local); +} + +void +initialization_by_redundantly_braced_string(void) +{ + any local = {{{{ "hello" }}}}; + use(&local); +} + +/* + * Only scalar expressions and string literals may be enclosed by additional + * braces. Since 'arg' is a struct, this is a compile-time error. + */ +void +initialization_with_too_many_braces(any arg) +{ + /* expect+1: error: cannot initialize 'pointer to const void' from 'struct any' [185] */ + any local = { arg }; + use(&arg); +} + +// Some of the following examples are mentioned in the introduction comment +// in init.c. + +int number = 12345; + +int number_with_braces_and_comma = { + 12345, +}; + +int array_with_fixed_size[3] = { + 111, + 222, + 333, + /* expect+1: error: too many array initializers, expected 3 [173] */ + 444, +}; + +// See update_type_of_array_of_unknown_size. +int array_of_unknown_size[] = { + 111, + 222, + 333, +}; + +int array_flat[2][2] = { + 11, + 12, + 21, + 22 +}; + +int array_nested[2][2] = { + { + 11, + 12 + }, + { + 21, + 22 + } +}; + +int array_with_designators[] = { + ['1'] = 111, + ['5'] = 555, + ['9'] = 999 +}; + +int array_with_some_designators[] = { + ['1'] = 111, + 222, + ['9'] = 999 +}; + +struct point { + int x; + int y; +}; + +struct point point = { + 3, + 4 +}; + +struct point point_with_designators = { + .y = 4, + .x = 3, +}; + +struct point point_with_mixed_designators = { + .x = 3, + 4, + /* expect+1: error: too many struct/union initializers [172] */ + 5, + .x = 3, +}; + +/* + * Before cgram.y 1.230 from 2021-06-20, the grammar allowed either of the + * operators '.' or '->' to be used for the designators and had extra code + * to ensure that only '.' was actually used. + */ +struct point origin = { + .x = 0, + /* expect+1: error: syntax error '->' [249] */ + ->y = 0, +}; + +/* Ensure that the parser can recover from the parse error. */ +struct point pythagoras = { 3, 4 }; + +int array_with_designator[] = { + 111, + /* expect+1: error: syntax error 'designator '.member' is only for struct/union' [249] */ + .member = 222, + 333, +}; + +/* + * C99 6.7.8p11 says that the initializer of a scalar can be "optionally + * enclosed in braces". It does not explicitly set an upper limit on the + * number of braces. It also doesn't restrict the term "initializer" to only + * mean the "outermost initializer". 6.7.8p13 defines that a brace for a + * structure or union always means to descend into the type. Both GCC 10 and + * Clang 8 already warn about these extra braces, nevertheless there is + * real-life code (the Postfix MTA) that exploits this corner case of the + * standard. + */ +struct point scalar_with_several_braces = { + {{{3}}}, + {{{{4}}}}, +}; + +struct rectangle { + struct point top_left; + struct point bottom_right; +}; + +/* C99 6.7.8p18 */ +struct rectangle screen = { + .bottom_right = { + 1920, + 1080, + } +}; + +/* + * C99 6.7.8p22 says: At the _end_ of its initializer list, the array no + * longer has incomplete type. + */ +struct point points[] = { + { + /* + * At this point, the size of the object 'points' is not known + * yet since its type is still incomplete. Lint could warn + * about this, but GCC and Clang already do. + * + * Before init.c 1.179 from 2021.03.30, the type information + * of 'points' was set too early, resulting in a negative + * array size below. + */ + sizeof(int[-(int)sizeof(points)]), + 4 + } +}; + + +struct triangle { + struct point points[3]; +}; + +struct pentagon { + struct point points[5]; +}; + +struct geometry { + struct pentagon pentagons[6]; + struct triangle triangles[10]; + struct point points[3][5][2]; +}; + +/* + * Initialization of a complex struct containing nested arrays and nested + * structs. + */ +struct geometry geometry = { + .pentagons[0].points[4].x = 1, + .points[0][0][0] = { 0, 0 }, + .points[2][4][1] = {301, 302 }, + /* expect+1: error: array subscript 3 cannot be > 2 [168] */ + .points[3][0][0] = {3001, 3002 }, + /* expect+1: error: array subscript 5 cannot be > 4 [168] */ + .points[0][5][0] = {501, 502 }, + /* expect+1: error: array subscript 2 cannot be > 1 [168] */ + .points[0][0][2] = {21, 22 }, +}; + +struct ends_with_unnamed_bit_field { + int member; + int:0; +} ends_with_unnamed_bit_field = { + 12345, + /* expect+1: error: too many struct/union initializers [172] */ + 23456, +}; + +char prefixed_message[] = { + 'E', ':', ' ', + /* expect+1: warning: invalid combination of integer 'char' and pointer 'pointer to char' for 'init' [183] */ + "message\n", +}; + +char message_with_suffix[] = { + "message", + /* The excess character is not detected by lint but by compilers. */ + '\n', +}; + +struct ten { + int i0; + int i1; + int i2; + int i3; + int i4; + int i5; + int i6; + int i7; + int i8; + int i9; +}; + +struct ten ten = { + .i3 = 3, + 4, + 5, + 6, +}; + + +/* + * ISO C99 6.7.8 provides a large list of examples for initialization, + * covering all tricky edge cases. + */ + +/* expect+1: warning: lossy conversion of 3.5 to 'int' [381] */ +int c99_6_7_8_p24_example1_i = 3.5; +double _Complex c99_6_7_8_p24_example1_c = 5 + 3 * 1.0fi; + +int c99_6_7_8_p25_example2[] = { 1, 3, 5 }; + +int c99_6_7_8_p26_example3a[4][3] = { + { 1, 3, 5 }, + { 2, 4, 6 }, + { 3, 5, 7 }, +}; + +int c99_6_7_8_p26_example3b[4][3] = { + 1, 3, 5, 2, 4, 6, 3, 5, 7 +}; + +int c99_6_7_8_p27_example4[4][3] = { + { 1 }, { 2 }, { 3 }, { 4 } +}; + +struct { + int a[3], b; +} c99_6_7_8_p28_example5[] = { + { 1 }, + 2, +}; + +short c99_6_7_8_p29_example6a[4][3][2] = { + { 1 }, + { 2, 3 }, + { 4, 5, 6 }, +}; + +short c99_6_7_8_p29_example6b[4][3][2] = { + 1, 0, 0, 0, 0, 0, + 2, 3, 0, 0, 0, 0, + 4, 5, 6, 0, 0, 0, +}; + +short c99_6_7_8_p29_example6c[4][3][2] = { + { + { 1 }, + }, + { + { 2, 3 }, + }, + { + { 4, 5 }, + { 6 }, + } +}; + +void +c99_6_7_8_p31_example7(void) +{ + typedef int A[]; + + A a = { 1, 2 }, b = { 3, 4, 5 }; + + /* expect+1: error: negative array dimension (-8) [20] */ + typedef int reveal_sizeof_a[-(int)(sizeof(a))]; + /* expect+1: error: negative array dimension (-12) [20] */ + typedef int reveal_sizeof_b[-(int)(sizeof(b))]; +} + +char c99_6_7_8_p32_example8_s1[] = "abc", + c99_6_7_8_p32_example8_t1[3] = "abc"; +char c99_6_7_8_p32_example8_s2[] = { 'a', 'b', 'c', '\0' }, + c99_6_7_8_p32_example8_t2[3] = { 'a', 'b', 'c' }; +char *c99_6_7_8_p32_example8_p = "abc"; + +enum { member_one, member_two }; +const char *c99_6_7_8_p33_example9[] = { + [member_two] = "member two", + [member_one] = "member one", +}; + +struct { + int quot, rem; +} c99_6_7_8_p34_example10 = { .quot = 2, .rem = -1 }; + +struct { int a[3], b; } c99_6_7_8_p35_example11[] = + { [0].a = {1}, [1].a[0] = 2 }; + +int c99_6_7_8_p36_example12a[16] = { + 1, 3, 5, 7, 9, [16-5] = 8, 6, 4, 2, 0 +}; + +int c99_6_7_8_p36_example12b[8] = { + 1, 3, 5, 7, 9, [8-5] = 8, 6, 4, 2, 0 +}; + +union { + int first_member; + void *second_member; + unsigned char any_member; +} c99_6_7_8_p38_example13 = { .any_member = 42 }; + + +/* + * During initialization of an object of type array of unknown size, the type + * information on the symbol is updated in-place. Ensure that this happens on + * a copy of the type. + * + * C99 6.7.8p31 example 7 + */ +void +ensure_array_type_is_not_modified_during_initialization(void) +{ + typedef int array_of_unknown_size[]; + + array_of_unknown_size a1 = { 1, 2, 3}; + + switch (4) { + case sizeof(array_of_unknown_size): + /* expect+1: error: duplicate case '0' in switch [199] */ + case 0: + case 3: + case 4: + case 12: + break; + } + + /* expect+1: error: negative array dimension (-12) [20] */ + typedef int reveal_sizeof_a1[-(int)(sizeof(a1))]; +} + +struct point unknown_member_name_beginning = { + /* expect+1: error: type 'struct point' does not have member 'r' [101] */ + .r = 5, + .x = 4, + .y = 3, +}; + +struct point unknown_member_name_middle = { + .x = 4, + /* expect+1: error: type 'struct point' does not have member 'r' [101] */ + .r = 5, + .y = 3, +}; + +struct point unknown_member_name_end = { + .x = 4, + .y = 3, + /* expect+1: error: type 'struct point' does not have member 'r' [101] */ + .r = 5, +}; + +union value { + int int_value; + void *pointer_value; +}; + +union value unknown_union_member_name_first = { + /* expect+1: error: type 'union value' does not have member 'unknown_value' [101] */ + .unknown_value = 4, + .int_value = 3, +}; + +union value unknown_union_member_name_second = { + .int_value = 3, + /* expect+1: error: type 'union value' does not have member 'unknown_value' [101] */ + .unknown_value = 4, +}; + +struct point subscript_designator_on_struct = { + /* expect+1: error: syntax error 'designator '[...]' is only for arrays' [249] */ + [0] = 3, +}; + +struct point unknown_member_on_struct = { + /* expect+1: error: type 'struct point' does not have member 'member' [101] */ + .member[0][0].member = 4, +}; + +struct point unknown_member_on_scalar = { + /* expect+1: error: syntax error 'scalar type cannot use designator' [249] */ + .x.y.z = 5, +}; + +struct { + int:16; + /* expect+2: warning: 'struct <unnamed>' has no named members [65] */ + /* expect+1: error: cannot initialize struct/union with no named member [179] */ +} struct_with_only_unnamed_members = { + 123, +}; + +union { + int:16; + /* expect+2: warning: 'union <unnamed>' has no named members [65] */ + /* expect+1: error: cannot initialize struct/union with no named member [179] */ +} union_with_only_unnamed_members = { + 123, +}; + +int designator_for_scalar = { + /* expect+1: error: syntax error 'scalar type cannot use designator' [249] */ + .value = 3, +}; + +struct point member_designator_for_scalar_in_struct = { + /* expect+1: error: syntax error 'scalar type cannot use designator' [249] */ + { .x = 3 }, +}; +struct point subscript_designator_for_scalar_in_struct = { + /* expect+1: error: syntax error 'designator '[...]' is only for arrays' [249] */ + { [1] = 4 }, +}; + + +/* Seen in pcidevs_data.h, variable 'pci_words'. */ +const char string_initialized_with_braced_literal[] = { + "initializer", +}; + +// An array of unknown size containing strings. +char weekday_names[][4] = { + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" +}; + +/* nested struct/union initialization */ +struct outer { + int i; + char c; + union inner { + short us; + char uc; + } u; + char *s; +} struct_containing_union[] = { + { + .s = "foo", + .c = 'b', + .u = { + .uc = 'c' + } + }, + { + .i = 1, + .c = 'a', + .u = { + .us = 2 + } + }, +}; + +/* + * The expansion of the offsetof macro may dereference a null pointer. + * Such expressions are allowed in initializers for objects with + * static duration. + */ +struct offset_and_data { + unsigned long offset; + unsigned long data; +}; + +struct offset_and_data offset_and_data = { + (unsigned long)&(((struct offset_and_data *)0)->data), + 0, +}; + +// The size of the array is determined by the maximum index, not by the last +// one mentioned. +int arr_11[] = { [10] = 10, [0] = 0 }; +/* expect+1: error: negative array dimension (-11) [20] */ +typedef int ctassert_11[-(int)(sizeof(arr_11) / sizeof(arr_11[0]))]; + +// Without an explicit subscript designator, the subscript counts up. +int arr_3[] = { [1] = 1, [0] = 0, 1, 2 }; +/* expect+1: error: negative array dimension (-3) [20] */ +typedef int ctassert_3[-(int)(sizeof(arr_3) / sizeof(arr_3[0]))]; + + +// C99 struct initialization using designators. +struct { + int i; + char *s; +} struct_array[] = { + { + .i = 2, + }, + { + .s = "foo" + }, + { + .i = 1, + .s = "bar" + }, + { + .s = "foo", + .i = -1 + }, +}; + +// Ensure that deeply nested structs can be designated in an initializer. +int +init_deeply_nested_struct(void) +{ + struct rgb { + unsigned red; + unsigned green; + unsigned blue; + }; + + struct hobbies { + unsigned dancing: 1; + unsigned running: 1; + unsigned swimming: 1; + }; + + struct person { + struct hobbies hobbies; + struct rgb favorite_color; + }; + + struct city { + struct person mayor; + }; + + struct state { + struct city capital; + }; + + struct state st = { + .capital.mayor.hobbies.dancing = 1, + .capital.mayor.favorite_color.green = 0xFF, + .capital.mayor.favorite_color.red = 0xFF, + }; + return st.capital.mayor.favorite_color.red; +} + +struct { + int i[10]; + char *s; +} struct_array_with_inner_array[] = { + { + { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, + "foo" + }, +}; + +struct { + int type; + union { + char b[20]; + short s[10]; + long l[5]; + } data; +} array_in_union_in_struct = { + .type = 3, + .data.l[0] = 4 +}; + +// Somewhere between 2005.12.24.20.47.56 and 2006.12.19.19.06.44, lint could +// not initialize named members, see PR bin/20264. +union { + char *p; + int a[1]; +} array_in_union = { + .a = { 7 } +}; + +/* + * Initialization of a nested struct, in which some parts are initialized + * from non-constant expressions of the inner struct type. + * + * In C99, 6.7.8p13 describes exactly this case. + */ +void +init_nested_struct(void) +{ + + typedef enum O1 { + O1C = 101 + } O1; + typedef enum O2 { + O2C = 102 + } O2; + typedef enum O3 { + O3C = 103 + } O3; + typedef enum I1 { + I1C = 201 + } I1; + typedef enum I2 { + I2C = 202 + } I2; + + struct Inner1 { + I1 i1; + }; + + struct Outer3Inner1 { + O1 o1; + struct Inner1 inner; + O3 o3; + }; + + struct Inner1 inner1 = { + I1C + }; + struct Outer3Inner1 o3i1 = { + O1C, + inner1, + O3C + }; + + O1 o1 = o3i1.o1; + + struct Inner2 { + I1 i1; + I2 i2; + }; + + struct Outer3Inner2 { + O1 o1; + struct Inner2 inner; + O3 o3; + }; + + struct Inner2 inner2 = { + I1C, + I2C + }; + struct Outer3Inner2 o3i2 = { + O1C, + inner2, + O3C + }; + o1 = o3i2.o1; + + /* + * For static storage duration, each initializer expression must be a + * constant expression. + */ + static struct Inner2 inner3_static = { + I1C, + I2C + }; + static struct Outer3Inner2 o3i2_static = { + O1C, + /* expect+1: error: non-constant initializer [177] */ + inner3_static, + O3C + }; +} diff --git a/usr.bin/xlint/lint1/lex_utf8.c b/usr.bin/xlint/lint1/lex_utf8.c new file mode 100644 index 000000000000..1146d1eb9511 --- /dev/null +++ b/usr.bin/xlint/lint1/lex_utf8.c @@ -0,0 +1,12 @@ +/* $NetBSD: lex_utf8.c,v 1.3 2024/02/03 10:56:18 rillig Exp $ */ +# 3 "lex_utf8.c" + +/* + * Test lexing of multibyte characters and strings in a UTF-8 locale. + * + * See also: + * lex_wide_string.c (runs in the C locale) + */ + +/* expect+1: error: negative array dimension (-3) [20] */ +typedef int mblen[-(int)(sizeof(L"Ä😄") / sizeof(L""))]; diff --git a/usr.bin/xlint/lint1/msg_079_nongcc.c b/usr.bin/xlint/lint1/msg_079_nongcc.c new file mode 100644 index 000000000000..c0b9a50ce132 --- /dev/null +++ b/usr.bin/xlint/lint1/msg_079_nongcc.c @@ -0,0 +1,26 @@ +/* $NetBSD: msg_079_nongcc.c,v 1.1 2024/02/02 19:07:58 rillig Exp $ */ +# 3 "msg_079_nongcc.c" + +// Test for message: dubious escape \%c [79] + +/* \e is only accepted in GCC mode. */ + +/* lint1-flags: -S -w -X 351 */ + +/* expect+1: warning: dubious escape \e [79] */ +char char_e = '\e'; +/* expect+1: warning: dubious escape \y [79] */ +char char_y = '\y'; +/* expect+1: warning: dubious escape \e [79] */ +int wide_e = L'\e'; +/* expect+1: warning: dubious escape \y [79] */ +int wide_y = L'\y'; + +/* expect+1: warning: dubious escape \e [79] */ +char char_string_e[] = "\e[0m"; +/* expect+1: warning: dubious escape \y [79] */ +char char_string_y[] = "\y[0m"; +/* expect+1: warning: dubious escape \e [79] */ +int wide_string_e[] = L"\e[0m"; +/* expect+1: warning: dubious escape \y [79] */ +int wide_string_y[] = L"\y[0m"; diff --git a/usr.bin/xlint/lint1/msg_118_ilp32.c b/usr.bin/xlint/lint1/msg_118_ilp32.c new file mode 100644 index 000000000000..abd78681305b --- /dev/null +++ b/usr.bin/xlint/lint1/msg_118_ilp32.c @@ -0,0 +1,47 @@ +/* $NetBSD: msg_118_ilp32.c,v 1.1 2025/09/06 20:18:41 rillig Exp $ */ +# 3 "msg_118_ilp32.c" + +/* Test for message: '%s' %s '%s' differs between traditional C and C90 [118] */ + +/* lint1-flags: -hw -X 351 */ +/* lint1-only-if: ilp32 */ + +int si; +unsigned ui; +long sl; +unsigned long ul; + +/* + * On 32-bit platforms both operands of the '<<' operator are first promoted + * individually, and since C90 does not know 'long long', the maximum + * bit-size for an integer type is 32 bits. + */ +void +test_shl(void) +{ + si <<= si; + si <<= ui; + si <<= sl; + si <<= ul; + + si = si << si; + si = si << ui; + si = si << sl; + si = si << ul; +} + +void +test_shr(void) +{ + si >>= si; + si >>= ui; + si >>= sl; + si >>= ul; + + si = si >> si; + /* expect+1: warning: 'int' >> 'unsigned int' differs between traditional C and C90 [118] */ + si = si >> ui; + si = si >> sl; + /* expect+1: warning: 'int' >> 'unsigned long' differs between traditional C and C90 [118] */ + si = si >> ul; +} diff --git a/usr.bin/xlint/lint1/msg_356.c b/usr.bin/xlint/lint1/msg_356.c new file mode 100644 index 000000000000..d7dbd28f4d13 --- /dev/null +++ b/usr.bin/xlint/lint1/msg_356.c @@ -0,0 +1,35 @@ +/* $NetBSD: msg_356.c,v 1.3 2024/03/25 22:37:43 rillig Exp $ */ +# 3 "msg_356.c" + +// Test for message: short octal escape '%.*s' followed by digit '%c' [356] + +/* lint1-extra-flags: -X 351 */ + +// When counting backwards in octal, the number before \040 is not \039 but +// \037. This mistake sometimes happens when encoding the bit numbers for +// snprintb(3) format conversions. + +char snprintb_fmt[] = "\020" + "\0040bit32" // 3-digit octal escapes are fine + "\0039bit31" + "\0038bit30" + + "\040bit32" + /* expect+1: warning: short octal escape '\03' followed by digit '9' [356] */ + "\039bit31" + /* expect+1: warning: short octal escape '\03' followed by digit '8' [356] */ + "\038bit30" + + "\40bit32" + /* expect+1: warning: short octal escape '\3' followed by digit '9' [356] */ + "\39bit31" + /* expect+1: warning: short octal escape '\3' followed by digit '8' [356] */ + "\38bit30" + "\37bit29" +; + +char ok[] = "" + "\3\70" // short octal followed by escaped '8' + "\3\x38" // short octal followed by escaped '8' + "\3" "8" // short octal and '8' are separated +; diff --git a/usr.bin/xlint/lint1/msg_357.c b/usr.bin/xlint/lint1/msg_357.c new file mode 100644 index 000000000000..e8f4d269076d --- /dev/null +++ b/usr.bin/xlint/lint1/msg_357.c @@ -0,0 +1,57 @@ +/* $NetBSD: msg_357.c,v 1.3 2024/11/05 06:23:04 rillig Exp $ */ +# 3 "msg_357.c" + +// Test for message: hex escape '%.*s' mixes uppercase and lowercase digits [357] + +/* + * In the format argument of the snprintb and snprintb_m functions, a bit + * position or field width is written as an octal or hexadecimal escape + * sequence. If the description that follows a hexadecimal escape sequence + * starts with hexadecimal digits (A-Fa-f), these digits are still part of the + * escape sequence instead of the description. + * + * Since the escape sequences are typically written in lowercase and the + * descriptions are typically written in uppercase, a mixture of both cases + * indicates a mismatch. + */ + +/* lint1-extra-flags: -X 351 */ + +typedef typeof(sizeof(0)) size_t; +typedef unsigned long long uint64_t; + +int snprintb(char *, size_t, const char *, uint64_t); + +void +examples(unsigned u32, uint64_t u64) +{ + char buf[64]; + + /* expect+5: warning: hex escape '\x0aB' mixes uppercase and lowercase digits [357] */ + /* expect+4: warning: hex escape '\x0aB' has more than 2 digits [358] */ + /* expect+3: warning: bit position '\x0aB' (171) in '\x0aBIT' out of range 1..32 [371] */ + snprintb(buf, sizeof(buf), + "\020\x0aBIT", + u32); + + // This mismatch goes undetected as it has only 2 digits, does not mix + // case and is in bounds. A spellchecker could mark the unknown word + // 'ield' to give a hint. + snprintb(buf, sizeof(buf), + "\020\x1FIELD", + u32); + + // If the input value is restricted further, the unintended hexadecimal + // escape sequence is detected, although with a less obvious message. + /* expect+3: warning: conversion '\x1FIELD' is unreachable by input value [378] */ + snprintb(buf, sizeof(buf), + "\020\x1FIELD", + u32 & 0xffff); + + /* expect+5: warning: hex escape '\x0aB' mixes uppercase and lowercase digits [357] */ + /* expect+4: warning: hex escape '\x0aB' has more than 2 digits [358] */ + /* expect+3: warning: bit position '\x0aB' (171) in 'b\x0aBIT\0' out of range 0..63 [371] */ + snprintb(buf, sizeof(buf), + "\177\020b\x0aBIT\0", + u64); +} diff --git a/usr.bin/xlint/lint1/msg_358.c b/usr.bin/xlint/lint1/msg_358.c new file mode 100644 index 000000000000..3e3799ff07a2 --- /dev/null +++ b/usr.bin/xlint/lint1/msg_358.c @@ -0,0 +1,65 @@ +/* $NetBSD: msg_358.c,v 1.4 2024/11/05 06:23:04 rillig Exp $ */ +# 3 "msg_358.c" + +// Test for message: hex escape '%.*s' has more than 2 digits [358] + +/* + * In the format argument of the snprintb and snprintb_m functions, a bit + * position or field width is written as an octal or hexadecimal escape + * sequence. If the description that follows a hexadecimal escape sequence + * starts with hexadecimal digits (A-Fa-f), these digits are still part of the + * escape sequence instead of the description. + * + * All platforms supported by lint have 8-bit char, so using more than the + * maximum necessary 2 hexadecimal digits in an escape sequence is suspicious + * of being unintended. + */ + +/* lint1-extra-flags: -X 351 */ + +typedef typeof(sizeof(0)) size_t; +typedef unsigned long long uint64_t; + +int snprintb(char *, size_t, const char *, uint64_t); + +void +examples(unsigned u32, uint64_t u64) +{ + char buf[64]; + + /* expect+3: warning: hex escape '\x01B' has more than 2 digits [358] */ + snprintb(buf, sizeof(buf), + "\020\x01BIT", + u32); + + /* expect+3: warning: hex escape '\x01b' has more than 2 digits [358] */ + snprintb(buf, sizeof(buf), + "\020\x01bit", + u32); + + // This mismatch goes undetected as it has only 2 digits, does not mix + // case and is in bounds. A spellchecker could mark the unknown word + // 'ield' to give a hint. + snprintb(buf, sizeof(buf), + "\020\x1FIELD", + u32); + + /* expect+3: warning: hex escape '\x01b' has more than 2 digits [358] */ + snprintb(buf, sizeof(buf), + "\177\020b\x01bit\0", + u64); + + /* expect+3: warning: hex escape '\x02b' has more than 2 digits [358] */ + snprintb(buf, sizeof(buf), + "\177\020f\x00\x02bit\0", + u64); + + // In this example from the snprintb manual page, the descriptions + // that start with a hexadecimal digit must be separated from the + // hexadecimal escape sequence for the bit position. + snprintb(buf, sizeof(buf), + "\20\x10NOTBOOT\x0f" "FPP\x0eSDVMA\x0cVIDEO" + "\x0bLORES\x0a" "FPA\x09" "DIAG\x07" "CACHE" + "\x06IOCACHE\x05LOOPBACK\x04" "DBGCACHE", + u32); +} diff --git a/usr.bin/xlint/lint1/msg_359.c b/usr.bin/xlint/lint1/msg_359.c new file mode 100644 index 000000000000..eb26e6093f19 --- /dev/null +++ b/usr.bin/xlint/lint1/msg_359.c @@ -0,0 +1,29 @@ +/* $NetBSD: msg_359.c,v 1.3 2024/11/05 06:23:04 rillig Exp $ */ +# 3 "msg_359.c" + +// Test for message: missing new-style '\177' or old-style number base [359] + +/* + * The first or second character of the snprintb format specifies the number + * base. It must be an octal or hexadecimal escape sequence, as the characters + * 2, 10 and 16 are not printable, and writing '\n' instead of '\x0a' would be + * misleading. + */ + +/* lint1-extra-flags: -X 351 */ + +typedef typeof(sizeof(0)) size_t; +typedef unsigned long long uint64_t; + +int snprintb(char *, size_t, const char *, uint64_t); + +void +old_style_number_base(void) +{ + char buf[64]; + + /* expect+1: warning: missing new-style '\177' or old-style number base [359] */ + snprintb(buf, sizeof(buf), "", 0); + snprintb(buf, sizeof(buf), "\010", 0); + snprintb(buf, sizeof(buf), "" "\177\020" "", 0); +} diff --git a/usr.bin/xlint/lint1/msg_360.c b/usr.bin/xlint/lint1/msg_360.c new file mode 100644 index 000000000000..dc3f208a36a7 --- /dev/null +++ b/usr.bin/xlint/lint1/msg_360.c @@ -0,0 +1,28 @@ +/* $NetBSD: msg_360.c,v 1.4 2024/11/05 06:23:04 rillig Exp $ */ +# 3 "msg_360.c" + +// Test for message: missing new-style number base after '\177' [360] + +/* + * The new-style format requires the number base as the second character. + * This check is merely a byproduct of the implementation, it provides little + * value of its own. + */ + +/* lint1-extra-flags: -X 351 */ + +typedef typeof(sizeof(0)) size_t; +typedef unsigned long long uint64_t; + +int snprintb(char *, size_t, const char *, uint64_t); + +void +new_style_number_base(void) +{ + char buf[64]; + + /* expect+1: warning: missing new-style number base after '\177' [360] */ + snprintb(buf, sizeof(buf), "\177", 0); + /* expect+1: warning: number base '\002' is 2, must be 8, 10 or 16 [361] */ + snprintb(buf, sizeof(buf), "\177\002", 0); +} diff --git a/usr.bin/xlint/lint1/msg_361.c b/usr.bin/xlint/lint1/msg_361.c new file mode 100644 index 000000000000..08b3c733ccb2 --- /dev/null +++ b/usr.bin/xlint/lint1/msg_361.c @@ -0,0 +1,52 @@ +/* $NetBSD: msg_361.c,v 1.4 2024/11/05 06:23:04 rillig Exp $ */ +# 3 "msg_361.c" + +// Test for message: number base '%.*s' is %ju, must be 8, 10 or 16 [361] + +/* + * The first or second character of the snprintb format specifies the number + * base. It must be given as an octal or hexadecimal escape sequence. + */ + +/* lint1-extra-flags: -X 351 */ + +typedef typeof(sizeof(0)) size_t; +typedef unsigned long long uint64_t; + +int snprintb(char *, size_t, const char *, uint64_t); + +void +old_style_number_base(void) +{ + char buf[64]; + + /* expect+1: warning: missing new-style '\177' or old-style number base [359] */ + snprintb(buf, sizeof(buf), "", 0); + /* expect+1: warning: number base '\002' is 2, must be 8, 10 or 16 [361] */ + snprintb(buf, sizeof(buf), "\002", 0); + snprintb(buf, sizeof(buf), "\010", 0); + snprintb(buf, sizeof(buf), "\n", 0); + snprintb(buf, sizeof(buf), "\020", 0); + /* expect+1: warning: number base '\014' is 12, must be 8, 10 or 16 [361] */ + snprintb(buf, sizeof(buf), "" "\014" "", 0); + snprintb(buf, sizeof(buf), "" "\020" "", 0); +} + +void +new_style_number_base(void) +{ + char buf[64]; + + /* expect+1: warning: missing new-style number base after '\177' [360] */ + snprintb(buf, sizeof(buf), "\177", 0); + /* expect+1: warning: number base '\0' is 0, must be 8, 10 or 16 [361] */ + snprintb(buf, sizeof(buf), "\177\0", 0); + /* expect+1: warning: number base '\002' is 2, must be 8, 10 or 16 [361] */ + snprintb(buf, sizeof(buf), "\177\002", 0); + snprintb(buf, sizeof(buf), "\177\010", 0); + snprintb(buf, sizeof(buf), "\177\n", 0); + snprintb(buf, sizeof(buf), "\177\020", 0); + /* expect+1: warning: number base '\014' is 12, must be 8, 10 or 16 [361] */ + snprintb(buf, sizeof(buf), "" "\177\014" "", 0); + snprintb(buf, sizeof(buf), "" "\177\020" "", 0); +} diff --git a/usr.bin/xlint/lint1/msg_362.c b/usr.bin/xlint/lint1/msg_362.c new file mode 100644 index 000000000000..58da2bd219e2 --- /dev/null +++ b/usr.bin/xlint/lint1/msg_362.c @@ -0,0 +1,33 @@ +/* $NetBSD: msg_362.c,v 1.4 2024/08/31 06:57:31 rillig Exp $ */ +# 3 "msg_362.c" + +// Test for message: conversion '%.*s' should not be escaped [362] + +/* + * Since the characters used for the conversion type were chosen to be easily + * readable, it doesn't make sense to obfuscate them. + */ + +/* lint1-extra-flags: -X 351 */ + +typedef typeof(sizeof(0)) size_t; +typedef unsigned long long uint64_t; + +int snprintb(char *, size_t, const char *, uint64_t); + +void +example(unsigned u32) +{ + char buf[64]; + + /* expect+9: warning: conversion '\142' should not be escaped [362] */ + /* expect+8: warning: bit position 'o' in '\142old-style-lsb\0' should be escaped as octal or hex [369] */ + /* expect+7: warning: bit position 'o' (111) in '\142old-style-lsb\0' out of range 0..63 [371] */ + /* expect+6: warning: unknown conversion '\001', must be one of 'bfF=:*' [374] */ + snprintb(buf, sizeof(buf), + "\177\020" + "\142old-style-lsb\0" + "\001old-style-lsb\0" + "\142\000old-style-lsb\0", + u32); +} diff --git a/usr.bin/xlint/lint1/msg_363.c b/usr.bin/xlint/lint1/msg_363.c new file mode 100644 index 000000000000..41a0e06845f2 --- /dev/null +++ b/usr.bin/xlint/lint1/msg_363.c @@ -0,0 +1,64 @@ +/* $NetBSD: msg_363.c,v 1.7 2024/11/05 06:23:04 rillig Exp $ */ +# 3 "msg_363.c" + +// Test for message: escaped character '%.*s' in description of conversion '%.*s' [363] + +/* + * The purpose of snprintb is to produce a printable, visible representation + * of a binary number, therefore the description should consist of simple + * characters only, and these should not need to be escaped. If they are, + * it's often due to a typo, such as a missing terminating '\0'. + */ + +/* lint1-extra-flags: -X 351 */ + +typedef typeof(sizeof(0)) size_t; +typedef unsigned long long uint64_t; + +int snprintb(char *, size_t, const char *, uint64_t); + +void +old_style_description(unsigned u32) +{ + char buf[64]; + + /* expect+6: warning: bit position '\t' in '\tprint' should be escaped as octal or hex [369] */ + /* expect+5: warning: escaped character '\377' in description of conversion '\nable\377' [363] */ + /* expect+4: warning: bit position '\n' in '\nable\377' should be escaped as octal or hex [369] */ + snprintb(buf, sizeof(buf), + "\020" + "\001non\tprint\nable\377", + u32); + + // In the new format, the description can technically contain + // arbitrary characters, but having non-printable characters would + // produce confusing output, so any escaped characters are suspicious + // of being unintended. + /* expect+6: warning: escaped character '\t' in description of conversion 'b\000non\t' [363] */ + /* expect+5: warning: escaped character '\n' in description of conversion 'b\000non\tprint\n' [363] */ + /* expect+4: warning: escaped character '\377' in description of conversion 'b\000non\tprint\nable\377' [363] */ + snprintb(buf, sizeof(buf), + "\177\020" + "b\000non\tprint\nable\377\0", + u32); + + /* expect+10: warning: escaped character '\177' in description of conversion '\002""\177' [363] */ + /* expect+9: warning: escaped character '\177' in description of conversion '\003aa""""\177' [363] */ + /* expect+8: warning: escaped character '\177' in description of conversion '\004""bb""\177' [363] */ + /* expect+7: warning: escaped character '\177' in description of conversion '\005""""cc\177' [363] */ + snprintb(buf, sizeof(buf), + "\020" + "\002""\177" + "\003aa""""\177" + "\004""bb""\177" + "\005""""cc\177", + u32); + + /* expect+6: warning: bit position '\000' (0) in '\000print' out of range 1..32 [371] */ + /* expect+5: warning: bit position '\n' in '\nable' should be escaped as octal or hex [369] */ + /* expect+4: warning: redundant '\0' at the end of the format [377] */ + snprintb(buf, sizeof(buf), + "\020" + "\001non\000print\nable\0", + u32); +} diff --git a/usr.bin/xlint/lint1/msg_364.c b/usr.bin/xlint/lint1/msg_364.c new file mode 100644 index 000000000000..61e24d4aa235 --- /dev/null +++ b/usr.bin/xlint/lint1/msg_364.c @@ -0,0 +1,35 @@ +/* $NetBSD: msg_364.c,v 1.4 2024/08/31 06:57:31 rillig Exp $ */ +# 3 "msg_364.c" + +// Test for message: missing bit position after '%.*s' [364] + +/* + * The conversions 'b', 'f' and 'F' require a bit position as their first + * argument. + */ + +/* lint1-extra-flags: -X 351 */ + +typedef typeof(sizeof(0)) size_t; +typedef unsigned long long uint64_t; + +int snprintb(char *, size_t, const char *, uint64_t); + +void +example(unsigned u32) +{ + char buf[64]; + + /* expect+4: warning: missing bit position after 'b' [364] */ + snprintb(buf, sizeof(buf), + "\177\020" + "b", + u32); + + /* expect+5: warning: empty description in 'b\007' [367] */ + /* expect+4: warning: missing '\0' at the end of 'b\007' [366] */ + snprintb(buf, sizeof(buf), + "\177\020" + "b\007", + u32); +} diff --git a/usr.bin/xlint/lint1/msg_365.c b/usr.bin/xlint/lint1/msg_365.c new file mode 100644 index 000000000000..f77fdc121a77 --- /dev/null +++ b/usr.bin/xlint/lint1/msg_365.c @@ -0,0 +1,34 @@ +/* $NetBSD: msg_365.c,v 1.4 2024/08/31 06:57:31 rillig Exp $ */ +# 3 "msg_365.c" + +// Test for message: missing field width after '%.*s' [365] + +/* + * The conversions 'f' and 'F' require a field width as their second argument. + */ + +/* lint1-extra-flags: -X 351 */ + +typedef typeof(sizeof(0)) size_t; +typedef unsigned long long uint64_t; + +int snprintb(char *, size_t, const char *, uint64_t); + +void +example(unsigned u32) +{ + char buf[64]; + + /* expect+4: warning: missing field width after 'f\000' [365] */ + snprintb(buf, sizeof(buf), + "\177\020" + "f\000", + u32); + + /* expect+5: warning: empty description in 'f\007\010' [367] */ + /* expect+4: warning: missing '\0' at the end of 'f\007\010' [366] */ + snprintb(buf, sizeof(buf), + "\177\020" + "f\007\010", + u32); +} diff --git a/usr.bin/xlint/lint1/msg_366.c b/usr.bin/xlint/lint1/msg_366.c new file mode 100644 index 000000000000..d6fd1884b302 --- /dev/null +++ b/usr.bin/xlint/lint1/msg_366.c @@ -0,0 +1,70 @@ +/* $NetBSD: msg_366.c,v 1.5 2024/08/31 06:57:31 rillig Exp $ */ +# 3 "msg_366.c" + +// Test for message: missing '\0' at the end of '%.*s' [366] + +/* + * In the new-style format, each conversion ends with a '\0'. If that's not + * the case, snprintb will read beyond the end of the format argument, looking + * for the terminating '\0'. In the most common case where the format comes + * from a string literal, the '\0' from the conversion needs to be spelled + * out, while the '\0' that terminates the sequence of conversions is provided + * by the C compiler. + */ + +/* lint1-extra-flags: -X 351 */ + +typedef typeof(sizeof(0)) size_t; +typedef unsigned long long uint64_t; + +int snprintb(char *, size_t, const char *, uint64_t); + +void +example(unsigned u32) +{ + char buf[64]; + + /* expect+4: warning: redundant '\0' at the end of the format [377] */ + snprintb(buf, sizeof(buf), + "\177\020" + "\0", + u32); + + /* expect+5: warning: empty description in 'b\007' [367] */ + /* expect+4: warning: missing '\0' at the end of 'b\007' [366] */ + snprintb(buf, sizeof(buf), + "\177\020" + "b\007", + u32); + + /* expect+5: warning: empty description in 'f\007\000' [367] */ + /* expect+4: warning: missing '\0' at the end of 'f\007\000' [366] */ + snprintb(buf, sizeof(buf), + "\177\020" + "f\007\000", + u32); + + /* expect+4: warning: missing '\0' at the end of 'F\007\000' [366] */ + snprintb(buf, sizeof(buf), + "\177\020" + "F\007\000", + u32); + + /* expect+4: warning: missing '\0' at the end of '=\007value' [366] */ + snprintb(buf, sizeof(buf), + "\177\020" + "=\007value", + u32); + + /* expect+4: warning: missing '\0' at the end of ':\007value' [366] */ + snprintb(buf, sizeof(buf), + "\177\020" + ":\007value", + u32); + + /* expect+4: warning: missing '\0' at the end of '*default' [366] */ + snprintb(buf, sizeof(buf), + "\177\020" + "*default", + u32); +} diff --git a/usr.bin/xlint/lint1/msg_367.c b/usr.bin/xlint/lint1/msg_367.c new file mode 100644 index 000000000000..5965098443e6 --- /dev/null +++ b/usr.bin/xlint/lint1/msg_367.c @@ -0,0 +1,120 @@ +/* $NetBSD: msg_367.c,v 1.4 2025/08/31 20:43:27 rillig Exp $ */ +# 3 "msg_367.c" + +// Test for message: empty description in '%.*s' [367] + +/* + * Each bit or field or comparison value gets a description. If such a + * description is empty, the generated output will contain empty angle + * brackets or multiple adjacent commas or commas adjacent to an angle + * bracket, such as '<,,,,>'. + */ + +/* lint1-extra-flags: -X 351 */ + +typedef typeof(sizeof(0)) size_t; +typedef unsigned long long uint64_t; + +int snprintb(char *, size_t, const char *, uint64_t); + +void +old_style(unsigned u32) +{ + char buf[64]; + + /* expect+10: warning: empty description in '\001' [367] */ + /* expect+9: warning: empty description in '\002' [367] */ + /* expect+8: warning: empty description in '\003' [367] */ + /* expect+7: warning: empty description in '\004' [367] */ + snprintb(buf, sizeof(buf), + "\020" + "\001" + "\002" + "\003" + "\004", + u32); + + /* expect+10: warning: empty description in '\001' [367] */ + /* expect+9: warning: empty description in '\002' [367] */ + /* expect+8: warning: empty description in '\003' [367] */ + /* expect+7: warning: empty description in '\004' [367] */ + snprintb(buf, sizeof(buf), + "\020" + "\001" "" "" + "\002" "" "" + "\003" "" "" + "\004" "" "", + u32); + + // Single-letter descriptions are not empty. + snprintb(buf, sizeof(buf), + "\020" + "\001a" + "\002b" + "\003c" + "\004d", + u32); +} + +void +new_style(uint64_t u64) +{ + char buf[64]; + + /* expect+4: warning: empty description in 'b\000\0' [367] */ + snprintb(buf, sizeof(buf), + "\177\020" + "b\000\0", + u64); + + /* expect+4: warning: empty description in 'f\000\010\0' [367] */ + snprintb(buf, sizeof(buf), + "\177\020" + "f\000\010\0", + u64); + + // No warning, as 'F' does not take a description. + // If there were a description, it would simply be skipped. + snprintb(buf, sizeof(buf), + "\177\020" + "F\000\010\0", + u64); + + /* expect+4: warning: empty description in '=\000\0' [367] */ + snprintb(buf, sizeof(buf), + "\177\020" + "=\000\0", + u64); + + /* expect+4: warning: empty description in ':\000\0' [367] */ + snprintb(buf, sizeof(buf), + "\177\020" + ":\000\0", + u64); + + /* expect+4: warning: empty description in '*\0' [367] */ + snprintb(buf, sizeof(buf), + "\177\020" + "*\0", + u64); + + // Single-letter descriptions are not empty. + snprintb(buf, sizeof(buf), + "\177\020" + "b\000b\0" + "f\001\001f\0" + "F\002\002F\0" + "=\000z\0" + ":\001o\0" + "*d\0", + /* expect+1: warning: conversion '=' does not mix with 'F' [386] */ + u64 >> 1); + + /* expect+6: warning: empty description in 'b\001""""""\0' [367] */ + /* expect+5: warning: empty description in 'b\003""""""\0' [367] */ + snprintb(buf, sizeof(buf), + "\177\020" + "b\001" "" "" "\0" + "b\003" "" "" "\0", + u64); +} diff --git a/usr.bin/xlint/lint1/msg_368.c b/usr.bin/xlint/lint1/msg_368.c new file mode 100644 index 000000000000..fd752f7cbbbf --- /dev/null +++ b/usr.bin/xlint/lint1/msg_368.c @@ -0,0 +1,34 @@ +/* $NetBSD: msg_368.c,v 1.3 2024/08/31 06:57:31 rillig Exp $ */ +# 3 "msg_368.c" + +// Test for message: missing comparison value after conversion '%.*s' [368] + +/* + * The conversions '=' and ':' require a comparison value as their argument, + * followed by the description and the terminating null character. + */ + +/* lint1-extra-flags: -X 351 */ + +typedef typeof(sizeof(0)) size_t; +typedef unsigned long long uint64_t; + +int snprintb(char *, size_t, const char *, uint64_t); + +void +example(uint64_t val) +{ + char buf[64]; + + /* expect+4: warning: missing comparison value after conversion '=' [368] */ + snprintb(buf, sizeof(buf), + "\177\020" + "=", + val); + + /* expect+4: warning: missing comparison value after conversion ':' [368] */ + snprintb(buf, sizeof(buf), + "\177\020" + ":", + val); +} diff --git a/usr.bin/xlint/lint1/msg_369.c b/usr.bin/xlint/lint1/msg_369.c new file mode 100644 index 000000000000..8129dc7b359b --- /dev/null +++ b/usr.bin/xlint/lint1/msg_369.c @@ -0,0 +1,52 @@ +/* $NetBSD: msg_369.c,v 1.3 2024/08/31 06:57:31 rillig Exp $ */ +# 3 "msg_369.c" + +// Test for message: bit position '%.*s' in '%.*s' should be escaped as octal or hex [369] + +/* + * To distinguish bit positions from the description text, they should use + * octal or hex escape sequences. Of these, octal escape sequences are less + * error-prone, as they consist of at most 3 octal digits, whereas hex escape + * sequences consume as many digits as available. + */ + +/* lint1-extra-flags: -X 351 */ + +typedef typeof(sizeof(0)) size_t; +typedef unsigned long long uint64_t; + +int snprintb(char *, size_t, const char *, uint64_t); + +void +example(unsigned u32, uint64_t u64) +{ + char buf[64]; + + /* expect+8: warning: bit position ' ' in ' space' should be escaped as octal or hex [369] */ + /* expect+7: warning: bit position '\t' in '\ttab' should be escaped as octal or hex [369] */ + /* expect+6: warning: bit position '\n' in '\nnewline' should be escaped as octal or hex [369] */ + snprintb(buf, sizeof(buf), + "\020" + " space" + "\ttab" + "\nnewline", + u32); + + /* expect+8: warning: bit position ' ' in 'b space\0' should be escaped as octal or hex [369] */ + /* expect+7: warning: bit position '\t' in 'b\ttab\0' should be escaped as octal or hex [369] */ + /* expect+6: warning: bit position '\n' in 'b\nnewline\0' should be escaped as octal or hex [369] */ + snprintb(buf, sizeof(buf), + "\177\020" + "b space\0" + "b\ttab\0" + "b\nnewline\0", + u64); + + /* expect+6: warning: bit position '\t' in 'f\t\001tab\0' should be escaped as octal or hex [369] */ + /* expect+5: warning: bit position '\n' in 'F\n\001newline\0' should be escaped as octal or hex [369] */ + snprintb(buf, sizeof(buf), + "\177\020" + "f\t\001tab\0" + "F\n\001newline\0", + u64); +} diff --git a/usr.bin/xlint/lint1/msg_370.c b/usr.bin/xlint/lint1/msg_370.c new file mode 100644 index 000000000000..e8c762c8deec --- /dev/null +++ b/usr.bin/xlint/lint1/msg_370.c @@ -0,0 +1,52 @@ +/* $NetBSD: msg_370.c,v 1.3 2024/08/31 06:57:31 rillig Exp $ */ +# 3 "msg_370.c" + +// Test for message: field width '%.*s' in '%.*s' should be escaped as octal or hex [370] + +/* + * To distinguish field widths from the description text, they should use + * octal or hex escape sequences. Of these, octal escape sequences are less + * error-prone, as they consist of at most 3 octal digits, whereas hex escape + * sequences consume as many digits as available. + */ + +/* lint1-extra-flags: -X 351 */ + +typedef typeof(sizeof(0)) size_t; +typedef unsigned long long uint64_t; + +int snprintb(char *, size_t, const char *, uint64_t); + +void +example(uint64_t u64) +{ + char buf[64]; + + /* expect+11: warning: bit position ' ' in 'f space\0' should be escaped as octal or hex [369] */ + /* expect+10: warning: field width ' ' in 'f space\0' should be escaped as octal or hex [370] */ + /* expect+9: warning: bit position '\t' in 'f\t\ttab\0' should be escaped as octal or hex [369] */ + /* expect+8: warning: field width '\t' in 'f\t\ttab\0' should be escaped as octal or hex [370] */ + /* expect+7: warning: bit position '\n' in 'f\n\nnewline\0' should be escaped as octal or hex [369] */ + /* expect+6: warning: field width '\n' in 'f\n\nnewline\0' should be escaped as octal or hex [370] */ + snprintb(buf, sizeof(buf), + "\177\020" + "f space\0" + "f\t\ttab\0" + "f\n\nnewline\0", + u64); + /* expect-1: warning: 'f\n\nnewline\0' overlaps earlier 'f\t\ttab\0' on bit 10 [376] */ + + /* expect+11: warning: bit position ' ' in 'F space\0' should be escaped as octal or hex [369] */ + /* expect+10: warning: field width ' ' in 'F space\0' should be escaped as octal or hex [370] */ + /* expect+9: warning: bit position '\t' in 'F\t\ttab\0' should be escaped as octal or hex [369] */ + /* expect+8: warning: field width '\t' in 'F\t\ttab\0' should be escaped as octal or hex [370] */ + /* expect+7: warning: bit position '\n' in 'F\n\nnewline\0' should be escaped as octal or hex [369] */ + /* expect+6: warning: field width '\n' in 'F\n\nnewline\0' should be escaped as octal or hex [370] */ + snprintb(buf, sizeof(buf), + "\177\020" + "F space\0" + "F\t\ttab\0" + "F\n\nnewline\0", + u64); + /* expect-1: warning: 'F\n\nnewline\0' overlaps earlier 'F\t\ttab\0' on bit 10 [376] */ +} diff --git a/usr.bin/xlint/lint1/msg_371.c b/usr.bin/xlint/lint1/msg_371.c new file mode 100644 index 000000000000..cb6ffdd54f20 --- /dev/null +++ b/usr.bin/xlint/lint1/msg_371.c @@ -0,0 +1,62 @@ +/* $NetBSD: msg_371.c,v 1.3 2024/08/31 06:57:31 rillig Exp $ */ +# 3 "msg_371.c" + +// Test for message: bit position '%.*s' (%ju) in '%.*s' out of range %u..%u [371] + +/* + * In old-style formats, bit positions are 1-based and must be in the range + * from 1 to 32. In new-style formats, bit positions are 0-based and must be + * in the range from 0 to 63. + */ + +/* lint1-extra-flags: -X 351 */ + +typedef typeof(sizeof(0)) size_t; +typedef unsigned long long uint64_t; + +int snprintb(char *, size_t, const char *, uint64_t); + +void +example(unsigned u32, uint64_t u64) +{ + char buf[64]; + + /* expect+12: warning: bit position '\000' (0) in '\000zero' out of range 1..32 [371] */ + /* expect+11: warning: escaped character '\041' in description of conversion '\040bit32""\041' [363] */ + /* expect+10: warning: escaped character '\177' in description of conversion '\040bit32""\041bit33""\177' [363] */ + /* expect+9: warning: escaped character '\377' in description of conversion '\040bit32""\041bit33""\177bit127""\377' [363] */ + snprintb(buf, sizeof(buf), + "\020" + "\000zero" + "\001bit1" + "\040bit32" + "\041bit33" + "\177bit127" + "\377bit255", + u32); + + /* expect+10: warning: bit position '\100' (64) in 'b\100bit64\0' out of range 0..63 [371] */ + /* expect+9: warning: bit position '\177' (127) in 'b\177bit127\0' out of range 0..63 [371] */ + /* expect+8: warning: bit position '\377' (255) in 'b\377bit255\0' out of range 0..63 [371] */ + snprintb(buf, sizeof(buf), + "\177\020" + "b\000bit0\0" + "b\077bit63\0" + "b\100bit64\0" + "b\177bit127\0" + "b\377bit255\0", + u64); + + /* expect+11: warning: bit position '\100' (64) in 'F\100\000none\0' out of range 0..63 [371] */ + /* expect+10: warning: bit position '\100' (64) in 'f\100\001oob\0' out of range 0..63 [371] */ + /* expect+9: warning: bit field end 65 in 'f\100\001oob\0' out of range 0..64 [373] */ + /* expect+8: warning: bit position '\101' (65) in 'F\101\001oob\0' out of range 0..63 [371] */ + /* expect+7: warning: bit field end 66 in 'F\101\001oob\0' out of range 0..64 [373] */ + snprintb(buf, sizeof(buf), + "\177\020" + "f\077\001msb\0" + "F\100\000none\0" + "f\100\001oob\0" + "F\101\001oob\0", + u64); +} diff --git a/usr.bin/xlint/lint1/msg_372.c b/usr.bin/xlint/lint1/msg_372.c new file mode 100644 index 000000000000..b4c914d75f64 --- /dev/null +++ b/usr.bin/xlint/lint1/msg_372.c @@ -0,0 +1,36 @@ +/* $NetBSD: msg_372.c,v 1.4 2024/08/31 06:57:31 rillig Exp $ */ +# 3 "msg_372.c" + +// Test for message: field width '%.*s' (%ju) in '%.*s' out of range 0..64 [372] + +/* + * In new-style formats, the width of a bit-field must be between 0 (an empty + * bit-field) and 64 (a bit-field spanning the whole value). + */ + +/* lint1-extra-flags: -X 351 */ + +typedef typeof(sizeof(0)) size_t; +typedef unsigned long long uint64_t; + +int snprintb(char *, size_t, const char *, uint64_t); + +void +example(uint64_t u64) +{ + char buf[64]; + + /* expect+12: warning: field width '\101' (65) in 'f\000\101all+1\0' out of range 0..64 [372] */ + /* expect+11: warning: bit field end 65 in 'f\000\101all+1\0' out of range 0..64 [373] */ + /* expect+10: warning: bit field end 65 in 'f\001\100oob64\0' out of range 0..64 [373] */ + /* expect+9: warning: 'f\001\100oob64\0' overlaps earlier 'f\000\100all\0' on bit 1 [376] */ + /* expect+8: warning: field width '\377' (255) in 'f\010\377oob64\0' out of range 0..64 [372] */ + /* expect+7: warning: bit field end 263 in 'f\010\377oob64\0' out of range 0..64 [373] */ + snprintb(buf, sizeof(buf), + "\177\020" + "f\000\100all\0" + "f\000\101all+1\0" + "f\001\100oob64\0" + "f\010\377oob64\0", + u64); +} diff --git a/usr.bin/xlint/lint1/msg_373.c b/usr.bin/xlint/lint1/msg_373.c new file mode 100644 index 000000000000..5eded6ff9e02 --- /dev/null +++ b/usr.bin/xlint/lint1/msg_373.c @@ -0,0 +1,44 @@ +/* $NetBSD: msg_373.c,v 1.4 2024/08/31 06:57:31 rillig Exp $ */ +# 3 "msg_373.c" + +// Test for message: bit field end %ju in '%.*s' out of range 0..64 [373] + +/* + * A bit-field may start in the middle of the value. When its end goes beyond + * 64, this means the uppermost bits will always be 0, and a narrower + * bit-field would have the same effect. + */ + +/* lint1-extra-flags: -X 351 */ + +typedef typeof(sizeof(0)) size_t; +typedef unsigned long long uint64_t; + +int snprintb(char *, size_t, const char *, uint64_t); + +void +example(uint64_t u64) +{ + char buf[64]; + + /* expect+12: warning: field width '\101' (65) in 'f\000\101all+1\0' out of range 0..64 [372] */ + /* expect+11: warning: bit field end 65 in 'f\000\101all+1\0' out of range 0..64 [373] */ + /* expect+10: warning: bit field end 65 in 'f\001\100oob64\0' out of range 0..64 [373] */ + /* expect+9: warning: 'f\001\100oob64\0' overlaps earlier 'f\000\100all\0' on bit 1 [376] */ + /* expect+8: warning: field width '\377' (255) in 'f\010\377oob64\0' out of range 0..64 [372] */ + /* expect+7: warning: bit field end 263 in 'f\010\377oob64\0' out of range 0..64 [373] */ + snprintb(buf, sizeof(buf), + "\177\020" + "f\000\100all\0" + "f\000\101all+1\0" + "f\001\100oob64\0" + "f\010\377oob64\0", + u64); + + /* expect+5: warning: bit position '\377' (255) in 'f\377\002wrap-around\0' out of range 0..63 [371] */ + /* expect+4: warning: bit field end 257 in 'f\377\002wrap-around\0' out of range 0..64 [373] */ + snprintb(buf, sizeof(buf), + "\177\020" + "f\377\002wrap-around\0", + u64); +} diff --git a/usr.bin/xlint/lint1/msg_374.c b/usr.bin/xlint/lint1/msg_374.c new file mode 100644 index 000000000000..1d4312623e58 --- /dev/null +++ b/usr.bin/xlint/lint1/msg_374.c @@ -0,0 +1,49 @@ +/* $NetBSD: msg_374.c,v 1.6 2024/08/31 06:57:31 rillig Exp $ */ +# 3 "msg_374.c" + +// Test for message: unknown conversion '%.*s', must be one of 'bfF=:*' [374] + +/* + * In the new-style format, an unknown conversion is assumed to have a single + * argument, followed by a null-terminated description. + */ + +/* lint1-extra-flags: -X 351 */ + +typedef typeof(sizeof(0)) size_t; +typedef unsigned long long uint64_t; + +int snprintb(char *, size_t, const char *, uint64_t); + +void +example(uint64_t u64) +{ + char buf[64]; + + /* expect+4: warning: unknown conversion 'x', must be one of 'bfF=:*' [374] */ + snprintb(buf, sizeof(buf), + "\177\020" + "x12345\0", + u64); + + /* expect+4: warning: unknown conversion '\000', must be one of 'bfF=:*' [374] */ + snprintb(buf, sizeof(buf), + "\177\020" + "\00012345\0", + u64); + + /* expect+5: warning: redundant '\0' at the end of the format [377] */ + snprintb(buf, sizeof(buf), + "\177\020" + "b\00012345\0" + "\0", + u64); + + // Real-life example: the '\b' is a typo. + // + /* expect+4: warning: unknown conversion '\b', must be one of 'bfF=:*' [374] */ + snprintb(buf, sizeof(buf), + "\177\020" + "b\15ENCNT\0b\16" "TC\0\b\20DSBL_CSR_DRN\0", + u64); +} diff --git a/usr.bin/xlint/lint1/msg_375.c b/usr.bin/xlint/lint1/msg_375.c new file mode 100644 index 000000000000..f8251c101d71 --- /dev/null +++ b/usr.bin/xlint/lint1/msg_375.c @@ -0,0 +1,38 @@ +/* $NetBSD: msg_375.c,v 1.4 2024/08/31 06:57:31 rillig Exp $ */ +# 3 "msg_375.c" + +// Test for message: comparison value '%.*s' (%ju) exceeds maximum field value %ju [375] + +/* + * When a bit field can take the values 0 to 15, there is no point comparing + * it to 16. + */ + +/* lint1-extra-flags: -X 351 */ + +typedef typeof(sizeof(0)) size_t; +typedef unsigned long long uint64_t; + +int snprintb(char *, size_t, const char *, uint64_t); + +void +example(uint64_t u64) +{ + char buf[64]; + + /* expect+14: warning: comparison value '\020' (16) exceeds maximum field value 15 [375] */ + /* expect+13: warning: comparison value '\377' (255) exceeds maximum field value 15 [375] */ + /* expect+12: warning: comparison value '\020' (16) exceeds maximum field value 15 [375] */ + /* expect+11: warning: comparison value '\377' (255) exceeds maximum field value 15 [375] */ + snprintb(buf, sizeof(buf), + "\177\020" + "f\000\004low\0" + "=\01715\0" + "=\02016\0" + "=\37716\0" + "F\004\004low\0" + ":\01715\0" + ":\02016\0" + ":\37716\0", + u64); +} diff --git a/usr.bin/xlint/lint1/msg_376.c b/usr.bin/xlint/lint1/msg_376.c new file mode 100644 index 000000000000..2e2135e869ae --- /dev/null +++ b/usr.bin/xlint/lint1/msg_376.c @@ -0,0 +1,58 @@ +/* $NetBSD: msg_376.c,v 1.4 2024/08/31 06:57:31 rillig Exp $ */ +# 3 "msg_376.c" + +// Test for message: '%.*s' overlaps earlier '%.*s' on bit %u [376] + +/* + * When bits and fields overlap, it's often due to typos or off-by-one errors. + */ + +/* lint1-extra-flags: -X 351 */ + +typedef typeof(sizeof(0)) size_t; +typedef unsigned long long uint64_t; + +int snprintb(char *, size_t, const char *, uint64_t); + +void +example(unsigned u32, uint64_t u64) +{ + char buf[64]; + + // In the old-style format, bit positions are 1-based. + snprintb(buf, sizeof(buf), + "\020" + "\001lsb" + "\x01lsb" + "\040msb" + "\x20msb" + "\041oob" + "\x21oob", + /* expect+4: warning: '\x01lsb' overlaps earlier '\001lsb' on bit 1 [376] */ + /* expect+3: warning: escaped character '\041' in description of conversion '\x20msb""\041' [363] */ + /* expect+2: warning: escaped character '\x21' in description of conversion '\x20msb""\041oob""\x21' [363] */ + /* expect+1: warning: '\x20msb""\041oob""\x21oob' overlaps earlier '\040msb' on bit 32 [376] */ + u32); + + // In the new-style format, bit positions are 0-based. + /* expect+10: warning: 'b\x00lsb\0' overlaps earlier 'b\000lsb\0' on bit 0 [376] */ + /* expect+9: warning: 'b\x3fmsb\0' overlaps earlier 'b\077msb\0' on bit 63 [376] */ + /* expect+8: warning: bit position '\x40' (64) in 'b\x40oob\0' out of range 0..63 [371] */ + snprintb(buf, sizeof(buf), + "\177\020" + "b\000lsb\0" + "b\x00lsb\0" + "b\077msb\0" + "b\x3fmsb\0" + "b\x40oob\0", + u64); + + /* expect+7: warning: 'F\014\010f2\0' overlaps earlier 'f\010\010f1\0' on bit 12 [376] */ + /* expect+6: warning: 'f\020\010f3\0' overlaps earlier 'F\014\010f2\0' on bit 16 [376] */ + snprintb(buf, sizeof(buf), + "\177\020" + "f\010\010f1\0" + "F\014\010f2\0" + "f\020\010f3\0", + u64); +} diff --git a/usr.bin/xlint/lint1/msg_377.c b/usr.bin/xlint/lint1/msg_377.c new file mode 100644 index 000000000000..0416ea6c1bb2 --- /dev/null +++ b/usr.bin/xlint/lint1/msg_377.c @@ -0,0 +1,41 @@ +/* $NetBSD: msg_377.c,v 1.5 2024/08/31 06:57:32 rillig Exp $ */ +# 3 "msg_377.c" + +// Test for message: redundant '\0' at the end of the format [377] + +/* + * Each conversion in the new-style format ends with a '\0' that needs to be + * spelled out. + * + * In both old-style and new-style formats, the '\0' that ends the whole + * format is provided by the compiler as part of the string literal. + */ + +/* lint1-extra-flags: -X 351 */ + +typedef typeof(sizeof(0)) size_t; +typedef unsigned long long uint64_t; + +int snprintb(char *, size_t, const char *, uint64_t); + +void +example(unsigned u32, uint64_t u64) +{ + char buf[64]; + + /* expect+7: warning: bit position '\000' (0) in '\000out-of-range' out of range 1..32 [371] */ + /* expect+6: warning: redundant '\0' at the end of the format [377] */ + snprintb(buf, sizeof(buf), + "\020" + "\005bit" + "\000out-of-range" + "\0", + u32); + + /* expect+5: warning: redundant '\0' at the end of the format [377] */ + snprintb(buf, sizeof(buf), + "\177\020" + "b\005bit\0" + "\0", + u64); +} diff --git a/usr.bin/xlint/lint1/msg_378.c b/usr.bin/xlint/lint1/msg_378.c new file mode 100644 index 000000000000..4698e99a9e9e --- /dev/null +++ b/usr.bin/xlint/lint1/msg_378.c @@ -0,0 +1,52 @@ +/* $NetBSD: msg_378.c,v 1.3 2024/08/31 06:57:32 rillig Exp $ */ +# 3 "msg_378.c" + +// Test for message: conversion '%.*s' is unreachable by input value [378] + +/* + * The typical use case of snprintb is to have a format that is specifically + * tailored to a particular input value. Often, a format is only used in a + * single place. Therefore, bits that are unreachable are redundant and may + * hint at typos. + */ + +/* lint1-extra-flags: -X 351 */ + +typedef typeof(sizeof(0)) size_t; +typedef unsigned long long uint64_t; + +int snprintb(char *, size_t, const char *, uint64_t); + +void +example(unsigned u32, uint64_t u64) +{ + char buf[64]; + + /* expect+5: warning: conversion '\040bit32' is unreachable by input value [378] */ + snprintb(buf, sizeof(buf), + "\020" + "\037bit31" + "\040bit32", + u32 >> 1); + + /* expect+5: warning: conversion 'b\075bit61\0' is unreachable by input value [378] */ + snprintb(buf, sizeof(buf), + "\177\020" + "b\074bit60\0" + "b\075bit61\0", + u64 >> 3); + + /* expect+12: warning: conversion 'b\000bit0\0' is unreachable by input value [378] */ + /* expect+11: warning: conversion 'b\011bit9\0' is unreachable by input value [378] */ + /* expect+10: warning: conversion 'f\017\002bits15-16\0' is unreachable by input value [378] */ + /* expect+9: warning: conversion 'f\050\030bits40-63\0' is unreachable by input value [378] */ + snprintb(buf, sizeof(buf), + "\177\020" + "b\000bit0\0" + "b\010bit8\0" + "b\011bit9\0" + "f\012\002bits10-11\0" + "f\017\002bits15-16\0" + "f\050\030bits40-63\0", + (u32 & 0xaa55aa55) << 8); +} diff --git a/usr.bin/xlint/lint1/msg_379.c b/usr.bin/xlint/lint1/msg_379.c new file mode 100644 index 000000000000..bb2b98917867 --- /dev/null +++ b/usr.bin/xlint/lint1/msg_379.c @@ -0,0 +1,31 @@ +/* $NetBSD: msg_379.c,v 1.2 2024/11/13 04:32:50 rillig Exp $ */ +# 3 "msg_379.c" + +// Test for message: comparing integer '%s' to floating point constant %Lg [379] + +/* + * Comparing an integer expression to a floating point constant mixes + * different kinds of types. This mixture is more complicated than necessary, + * thus confusing human readers. + * + * The compilers are fine with this kind of expression: GCC treats the + * constant as an integer even at -O0 while Clang needs at least -O. + */ + +/* lint1-extra-flags: -X 351 */ + +int +comparisons(int x) +{ + if (3 > 123.0) + /* expect+1: warning: 'return' statement not reached [193] */ + return 0; + /* expect+1: warning: comparing integer 'int' to floating point constant 123 [379] */ + if (x > 123.0) + return 1; + + // Yoda-style comparisons are unusual enough to not warn about them. + if (123.0 > x) + return 2; + return 3; +} diff --git a/usr.bin/xlint/lint1/msg_380.c b/usr.bin/xlint/lint1/msg_380.c new file mode 100644 index 000000000000..b729380789a3 --- /dev/null +++ b/usr.bin/xlint/lint1/msg_380.c @@ -0,0 +1,71 @@ +/* $NetBSD: msg_380.c,v 1.2 2024/06/22 06:24:46 rillig Exp $ */ +# 3 "msg_380.c" + +// Test for message: lossy conversion of %Lg to '%s', arg #%d [380] + +/* lint1-extra-flags: -X 351 */ + +void take_s32(int); +void take_u32(unsigned int); +void take_s64(long long); +void take_u64(unsigned long long); + +void +conversions(void) +{ + /* expect+1: warning: lossy conversion of -2.14748e+09 to 'int', arg #1 [380] */ + take_s32(-2147483649.0); + take_s32(-2147483648.0); + /* expect+1: warning: lossy conversion of 3.141 to 'int', arg #1 [380] */ + take_s32(3.141); + take_s32(2147483647.0); + /* expect+1: warning: lossy conversion of 2.14748e+09 to 'int', arg #1 [380] */ + take_s32(2147483648.0); + + /* expect+1: warning: lossy conversion of -1 to 'unsigned int', arg #1 [380] */ + take_u32(-1.0); + take_u32(-0.0); + take_u32(0.0); + /* expect+1: warning: lossy conversion of 3.141 to 'unsigned int', arg #1 [380] */ + take_u32(3.141); + take_u32(4294967295.0); + /* expect+1: warning: lossy conversion of 4.29497e+09 to 'unsigned int', arg #1 [380] */ + take_u32(4294967296.0); + + /* expect+1: warning: lossy conversion of -9.22337e+18 to 'long long', arg #1 [380] */ + take_s64(-9223372036854776833.0); + /* The constant ...809 is rounded down to ...808, thus no warning. */ + take_s64(-9223372036854775809.0); + take_s64(-9223372036854775808.0); + /* expect+1: warning: lossy conversion of 3.141 to 'long long', arg #1 [380] */ + take_s64(3.141); + /* expect+1: warning: lossy conversion of 9.22337e+18 to 'long long', arg #1 [380] */ + take_s64(9223372036854775807.0); + /* expect+1: warning: lossy conversion of 9.22337e+18 to 'long long', arg #1 [380] */ + take_s64(9223372036854775808.0); + + /* expect+1: warning: lossy conversion of -1 to 'unsigned long long', arg #1 [380] */ + take_u64(-1.0); + take_u64(-0.0); + take_u64(0.0); + /* expect+1: warning: lossy conversion of 3.141 to 'unsigned long long', arg #1 [380] */ + take_u64(3.141); + + // Warning on: alpha + // No warning on: aarch64 aarch64-compat32 arm i386 mips powerpc riscv64 sh3 sparc x86_64 + // Unknown: coldfire hppa ia64 m68000 m68k mips64 mipsn64 or1k powerpc64 riscv32 sparc64 vax + // + // warning: lossy conversion of 1.84467e+19 to 'unsigned long long', arg #1 [380] + //take_u64(18446744073709550591.0); + + // Warning on: aarch64 alpha arm i386 mips riscv64 sparc x86_64 + // No warning on: aarch64-compat32 powerpc sh3 + // Unknown: coldfire hppa ia64 m68000 m68k mips64 mipsn64 or1k powerpc64 riscv32 sparc64 vax + // + // warning: lossy conversion of 1.84467e+19 to 'unsigned long long', arg #1 [380] + //take_u64(18446744073709550592.0); + // warning: lossy conversion of 1.84467e+19 to 'unsigned long long', arg #1 [380] + //take_u64(18446744073709551615.0); + // warning: lossy conversion of 1.84467e+19 to 'unsigned long long', arg #1 [380] + //take_u64(18446744073709551616.0); +} diff --git a/usr.bin/xlint/lint1/msg_381.c b/usr.bin/xlint/lint1/msg_381.c new file mode 100644 index 000000000000..4bf64e3cf895 --- /dev/null +++ b/usr.bin/xlint/lint1/msg_381.c @@ -0,0 +1,71 @@ +/* $NetBSD: msg_381.c,v 1.2 2024/06/22 06:24:46 rillig Exp $ */ +# 3 "msg_381.c" + +// Test for message: lossy conversion of %Lg to '%s' [381] + +/* lint1-extra-flags: -X 351 */ + +int s32; +unsigned int u32; +long long s64; +unsigned long long u64; + +void +conversions(void) +{ + /* expect+1: warning: lossy conversion of -2.14748e+09 to 'int' [381] */ + s32 = -2147483649.0; + s32 = -2147483648.0; + /* expect+1: warning: lossy conversion of 3.141 to 'int' [381] */ + s32 = 3.141; + s32 = 2147483647.0; + /* expect+1: warning: lossy conversion of 2.14748e+09 to 'int' [381] */ + s32 = 2147483648.0; + + /* expect+1: warning: lossy conversion of -1 to 'unsigned int' [381] */ + u32 = -1.0; + u32 = -0.0; + u32 = 0.0; + /* expect+1: warning: lossy conversion of 3.141 to 'unsigned int' [381] */ + u32 = 3.141; + u32 = 4294967295.0; + /* expect+1: warning: lossy conversion of 4.29497e+09 to 'unsigned int' [381] */ + u32 = 4294967296.0; + + /* expect+1: warning: lossy conversion of -9.22337e+18 to 'long long' [381] */ + s64 = -9223372036854776833.0; + /* The constant ...809 is rounded down to ...808, thus no warning. */ + s64 = -9223372036854775809.0; + s64 = -9223372036854775808.0; + /* expect+1: warning: lossy conversion of 3.141 to 'long long' [381] */ + s64 = 3.141; + /* expect+1: warning: lossy conversion of 9.22337e+18 to 'long long' [381] */ + s64 = 9223372036854775807.0; + /* expect+1: warning: lossy conversion of 9.22337e+18 to 'long long' [381] */ + s64 = 9223372036854775808.0; + + /* expect+1: warning: lossy conversion of -1 to 'unsigned long long' [381] */ + u64 = -1.0; + u64 = -0.0; + u64 = 0.0; + /* expect+1: warning: lossy conversion of 3.141 to 'unsigned long long' [381] */ + u64 = 3.141; + + // Warning on: alpha + // No warning on: aarch64 aarch64-compat32 arm i386 mips powerpc riscv64 sh3 sparc x86_64 + // Unknown: coldfire hppa ia64 m68000 m68k mips64 mipsn64 or1k powerpc64 riscv32 sparc64 vax + // + // warning: lossy conversion of 1.84467e+19 to 'unsigned long long' [381] + //u64 = 18446744073709550591.0; + + // Warning on: aarch64 alpha arm i386 mips riscv64 sparc x86_64 + // No warning on: aarch64-compat32 powerpc sh3 + // Unknown: coldfire hppa ia64 m68000 m68k mips64 mipsn64 or1k powerpc64 riscv32 sparc64 vax + // + // warning: lossy conversion of 1.84467e+19 to 'unsigned long long' [381] + //u64 = 18446744073709550592.0; + // warning: lossy conversion of 1.84467e+19 to 'unsigned long long' [381] + //u64 = 18446744073709551615.0; + // warning: lossy conversion of 1.84467e+19 to 'unsigned long long' [381] + //u64 = 18446744073709551616.0; +} diff --git a/usr.bin/xlint/lint1/msg_382.c b/usr.bin/xlint/lint1/msg_382.c new file mode 100644 index 000000000000..6b72ce0c4071 --- /dev/null +++ b/usr.bin/xlint/lint1/msg_382.c @@ -0,0 +1,42 @@ +/* $NetBSD: msg_382.c,v 1.2 2025/04/12 17:22:50 rillig Exp $ */ +# 3 "msg_382.c" + +// Test for message: constant assignment of type '%s' in operand of '%s' always evaluates to '%s' [382] + +/* + * Outside strict bool mode, an assignment can be used as a condition, but + * that is generally wrong. Especially if a constant is assigned to a + * variable, the condition always evaluates to that constant value, which + * indicates a typo, as '==' makes more sense than '=' in a condition. + */ + +/* lint1-extra-flags: -X 351 */ + +int +conversions(int a, int b) +{ + /* expect+1: warning: constant assignment of type 'int' in operand of '!' always evaluates to 'true' [382] */ + if (!(a = 13)) + return 1; + /* expect+1: warning: constant assignment of type 'int' in operand of '!' always evaluates to 'false' [382] */ + if (!(b = 0)) + return 2; + if (!(a = a + 1)) + return 3; + + /* expect+1: warning: constant assignment of type 'int' in operand of '&&' always evaluates to 'true' [382] */ + if ((a = 13) && (b == 14)) + return 4; + /* expect+1: warning: constant assignment of type 'int' in operand of '&&' always evaluates to 'true' [382] */ + if ((a == 13) && (b = 14)) + return 5; + + /* expect+1: warning: constant assignment of type 'int' in operand of '||' always evaluates to 'true' [382] */ + if ((a = 13) || (b == 14)) + return 4; + /* expect+1: warning: constant assignment of type 'int' in operand of '||' always evaluates to 'true' [382] */ + if ((a == 13) || (b = 14)) + return 5; + + return a; +} diff --git a/usr.bin/xlint/lint1/msg_383.c b/usr.bin/xlint/lint1/msg_383.c new file mode 100644 index 000000000000..7bfee2d6d34d --- /dev/null +++ b/usr.bin/xlint/lint1/msg_383.c @@ -0,0 +1,56 @@ +/* $NetBSD: msg_383.c,v 1.4 2025/05/04 09:40:03 rillig Exp $ */ +# 3 "msg_383.c" + +// Test for message: passing '%s' as argument %d to '%s' discards '%s' [383] + +/* lint1-extra-flags: -X 351 */ + +void sink_char(char *, const char *, volatile char *, const volatile char *); +void sink_int(int *, const int *, volatile int *, const volatile int *); + +void (*indirect_char)(char *, const char *, volatile char *, const volatile char *); + +struct { + void (*member_char)(char *, const char *, volatile char *, const volatile char *); +} doubly_indirect; + +void +caller(const volatile char *cvcp, const volatile int *cvip, int (*fn)(void)) +{ + /* expect+3: warning: passing 'pointer to const volatile char' as argument 1 to 'sink_char' discards 'const volatile' [383] */ + /* expect+2: warning: passing 'pointer to const volatile char' as argument 2 to 'sink_char' discards 'volatile' [383] */ + /* expect+1: warning: passing 'pointer to const volatile char' as argument 3 to 'sink_char' discards 'const' [383] */ + sink_char(cvcp, cvcp, cvcp, cvcp); + /* expect+3: warning: passing 'pointer to const volatile int' as argument 1 to 'sink_int' discards 'const volatile' [383] */ + /* expect+2: warning: passing 'pointer to const volatile int' as argument 2 to 'sink_int' discards 'volatile' [383] */ + /* expect+1: warning: passing 'pointer to const volatile int' as argument 3 to 'sink_int' discards 'const' [383] */ + sink_int(cvip, cvip, cvip, cvip); + /* expect+4: warning: converting 'pointer to function(void) returning int' to incompatible 'pointer to char' for argument 1 [153] */ + /* expect+3: warning: converting 'pointer to function(void) returning int' to incompatible 'pointer to const char' for argument 2 [153] */ + /* expect+2: warning: converting 'pointer to function(void) returning int' to incompatible 'pointer to volatile char' for argument 3 [153] */ + /* expect+1: warning: converting 'pointer to function(void) returning int' to incompatible 'pointer to const volatile char' for argument 4 [153] */ + sink_char(fn, fn, fn, fn); + + /* expect+3: warning: passing 'pointer to const volatile char' as argument 1 to 'indirect_char' discards 'const volatile' [383] */ + /* expect+2: warning: passing 'pointer to const volatile char' as argument 2 to 'indirect_char' discards 'volatile' [383] */ + /* expect+1: warning: passing 'pointer to const volatile char' as argument 3 to 'indirect_char' discards 'const' [383] */ + indirect_char(cvcp, cvcp, cvcp, cvcp); + + /* expect+3: warning: passing 'pointer to const volatile char' as argument 1 to 'function(pointer to char, pointer to const char, pointer to volatile char, pointer to const volatile char) returning void' discards 'const volatile' [383] */ + /* expect+2: warning: passing 'pointer to const volatile char' as argument 2 to 'function(pointer to char, pointer to const char, pointer to volatile char, pointer to const volatile char) returning void' discards 'volatile' [383] */ + /* expect+1: warning: passing 'pointer to const volatile char' as argument 3 to 'function(pointer to char, pointer to const char, pointer to volatile char, pointer to const volatile char) returning void' discards 'const' [383] */ + doubly_indirect.member_char(cvcp, cvcp, cvcp, cvcp); +} + + +typedef int array[8]; +typedef const int *pointer_to_const_array; + +// The 'const' applies to the pointer target, making it 'const int *'. +int const_array_callee(const array); + +static inline int +const_array_caller(pointer_to_const_array ptr) +{ + return const_array_callee(ptr); +} diff --git a/usr.bin/xlint/lint1/msg_384.c b/usr.bin/xlint/lint1/msg_384.c new file mode 100644 index 000000000000..9c7d21377c26 --- /dev/null +++ b/usr.bin/xlint/lint1/msg_384.c @@ -0,0 +1,26 @@ +/* $NetBSD: msg_384.c,v 1.2 2025/01/03 03:14:47 rillig Exp $ */ +# 3 "msg_384.c" + +// Test for message: function definition for '%s' with identifier list is obsolete in C23 [384] + +/* lint1-extra-flags: -X 351 */ + +/* + * In traditional C, defining a function by listing its parameter names first, + * followed by declarations, was usual. This practice has been obsoleted in + * favor of defining the parameter types right in the declarator. + */ + +static inline int +/* expect+1: warning: function definition for 'function_with_identifier_list' with identifier list is obsolete in C23 [384] */ +function_with_identifier_list(a, b) + int a, b; +{ + return a + b; +} + +static inline int +function_with_prototype(int a, int b) +{ + return a + b; +} diff --git a/usr.bin/xlint/lint1/msg_385.c b/usr.bin/xlint/lint1/msg_385.c new file mode 100644 index 000000000000..fdc749066e06 --- /dev/null +++ b/usr.bin/xlint/lint1/msg_385.c @@ -0,0 +1,58 @@ +/* $NetBSD: msg_385.c,v 1.2 2025/03/10 22:08:36 rillig Exp $ */ +# 3 "msg_385.c" + +// Test for message: do-while macro '%.*s' ends with semicolon [385] + +/* + * A function-like macro that consists of a do-while statement is intended to + * expand to a single statement, but without the trailing semicolon, as the + * semicolon is already provided by the calling site. When the macro expansion + * ends with a semicolon, there are two semicolons, which can lead to syntax + * errors. + */ + +/* lint1-extra-flags: -X 351 */ + +/* expect+1: warning: do-while macro 'wrong_stmt' ends with semicolon [385] */ +#define wrong_stmt() do { } while (0); + +#define correct_stmt() do { } while (0) + +/* expect+5: warning: do-while macro 'wrong_stmt_with_comment' ends with semicolon [385] */ +#define wrong_stmt_with_comment() do { } while (0); /* +a +b +c +*/ + +#define correct_stmt_with_comment() do { } while (0) /* +a +b +c +*/ + +/* The comment marker inside the string literal does not start a comment. */ +#define stmt_with_string() do { print("/*"); } while (0) + +void +call_wrong_stmt(int x) +{ + if (x > 0) + do { } while (0);; + /* expect+1: error: syntax error 'else' [249] */ + else + do { } while (0);; +} + +void +call_correct_stmt(int x) +{ + if (x < 0) + do { } while (0); + else + do { } while (0); +} + +// The macro expansion does start with "do", but not with the keyword "do", +// so don't warn in this case. +#define unrelated() do_something(); diff --git a/usr.bin/xlint/lint1/msg_386.c b/usr.bin/xlint/lint1/msg_386.c new file mode 100644 index 000000000000..fd46580be6c7 --- /dev/null +++ b/usr.bin/xlint/lint1/msg_386.c @@ -0,0 +1,34 @@ +/* $NetBSD: msg_386.c,v 1.1 2025/08/31 20:43:27 rillig Exp $ */ +# 3 "msg_386.c" + +// Test for message: conversion '%.*s' does not mix with '%c' [386] + +/* + * In the snprintb format string, the conversions 'f' and '=' mix well, and so + * do 'F' and ':'. But 'f' doesn't mix with ':', and neither does 'F' mix with + * '='. + */ + +/* lint1-extra-flags: -X 351 */ + +typedef typeof(sizeof 0) size_t; + +void snprintb(char *, size_t, const char *, unsigned long long); + +void +test_snprintb(void) +{ + char buf[50]; + + snprintb(buf, sizeof buf, + "\177\020" + "f\000\020" "field\0" + "" "=\000" "mix\0" + "" ":\001" "no-mix\0" + "F\020\020" "field\0" + "" "=\000" "no-mix\0" + "" ":\000" "mix\0", + /* expect+2: warning: conversion ':' does not mix with 'f' [386] */ + /* expect+1: warning: conversion '=' does not mix with 'F' [386] */ + 0xffffffff); +} diff --git a/usr.bin/xlint/lint1/platform_ilp32_c90.c b/usr.bin/xlint/lint1/platform_ilp32_c90.c new file mode 100644 index 000000000000..73702b2c3f58 --- /dev/null +++ b/usr.bin/xlint/lint1/platform_ilp32_c90.c @@ -0,0 +1,243 @@ +/* $NetBSD: platform_ilp32_c90.c,v 1.3 2024/01/28 08:26:07 rillig Exp $ */ +# 3 "platform_ilp32_c90.c" + +/* + * Tests that are specific to ILP32 platforms and the language level C90. + */ + +/* lint1-flags: -sw -X 351 */ +/* lint1-only-if: ilp32 */ + +void *lex_integer[] = { + /* expect+1: ... integer 'int' ... */ + 2147483647, + /* expect+1: ... integer 'int' ... */ + 0x7fffffff, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 2147483648, + /* expect+1: ... integer 'unsigned int' ... */ + 0x80000000, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 4294967295, + /* expect+1: ... integer 'unsigned int' ... */ + 0xffffffff, + /* expect+1: warning: integer constant out of range [252] */ + 4294967296, + /* expect+1: warning: integer constant out of range [252] */ + 0x0000000100000000, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 9223372036854775807, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 0x7fffffffffffffff, + /* expect+1: warning: integer constant out of range [252] */ + 9223372036854775808, + /* expect+1: warning: integer constant out of range [252] */ + 0x8000000000000000, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 18446744073709551615, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 0xffffffffffffffff, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 18446744073709551616, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 0x00010000000000000000, + + /* expect+1: ... integer 'unsigned int' ... */ + 2147483647U, + /* expect+1: ... integer 'unsigned int' ... */ + 0x7fffffffU, + /* expect+1: ... integer 'unsigned int' ... */ + 2147483648U, + /* expect+1: ... integer 'unsigned int' ... */ + 0x80000000U, + /* expect+1: ... integer 'unsigned int' ... */ + 4294967295U, + /* expect+1: ... integer 'unsigned int' ... */ + 0xffffffffU, + /* expect+1: warning: integer constant out of range [252] */ + 4294967296U, + /* expect+1: warning: integer constant out of range [252] */ + 0x0000000100000000U, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 9223372036854775807U, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 0x7fffffffffffffffU, + /* expect+1: warning: integer constant out of range [252] */ + 9223372036854775808U, + /* expect+1: warning: integer constant out of range [252] */ + 0x8000000000000000U, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 18446744073709551615U, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 0xffffffffffffffffU, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 18446744073709551616U, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 0x00010000000000000000U, + + /* expect+1: ... integer 'long' ... */ + 2147483647L, + /* expect+1: ... integer 'long' ... */ + 0x7fffffffL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 2147483648L, + /* expect+1: ... integer 'unsigned long' ... */ + 0x80000000L, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 4294967295L, + /* expect+1: ... integer 'unsigned long' ... */ + 0xffffffffL, + /* expect+1: warning: integer constant out of range [252] */ + 4294967296L, + /* expect+1: warning: integer constant out of range [252] */ + 0x0000000100000000L, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 9223372036854775807L, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 0x7fffffffffffffffL, + /* expect+1: warning: integer constant out of range [252] */ + 9223372036854775808L, + /* expect+1: warning: integer constant out of range [252] */ + 0x8000000000000000L, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 18446744073709551615L, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 0xffffffffffffffffL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 18446744073709551616L, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 0x00010000000000000000L, + + /* expect+1: ... integer 'unsigned long' ... */ + 2147483647UL, + /* expect+1: ... integer 'unsigned long' ... */ + 0x7fffffffUL, + /* expect+1: ... integer 'unsigned long' ... */ + 2147483648UL, + /* expect+1: ... integer 'unsigned long' ... */ + 0x80000000UL, + /* expect+1: ... integer 'unsigned long' ... */ + 4294967295UL, + /* expect+1: ... integer 'unsigned long' ... */ + 0xffffffffUL, + /* expect+1: warning: integer constant out of range [252] */ + 4294967296UL, + /* expect+1: warning: integer constant out of range [252] */ + 0x0000000100000000UL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 9223372036854775807UL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 0x7fffffffffffffffUL, + /* expect+1: warning: integer constant out of range [252] */ + 9223372036854775808UL, + /* expect+1: warning: integer constant out of range [252] */ + 0x8000000000000000UL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 18446744073709551615UL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 0xffffffffffffffffUL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 18446744073709551616UL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 0x00010000000000000000UL, + + /* expect+1: ... integer 'long long' ... */ + 2147483647LL, + /* expect+1: ... integer 'long long' ... */ + 0x7fffffffLL, + /* expect+1: ... integer 'long long' ... */ + 2147483648LL, + /* expect+1: ... integer 'long long' ... */ + 0x80000000LL, + /* expect+1: ... integer 'long long' ... */ + 4294967295LL, + /* expect+1: ... integer 'long long' ... */ + 0xffffffffLL, + /* expect+1: ... integer 'long long' ... */ + 4294967296LL, + /* expect+1: ... integer 'long long' ... */ + 0x0000000100000000LL, + /* expect+1: ... integer 'long long' ... */ + 9223372036854775807LL, + /* expect+1: ... integer 'long long' ... */ + 0x7fffffffffffffffLL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 9223372036854775808LL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0x8000000000000000LL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 18446744073709551615LL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0xffffffffffffffffLL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 18446744073709551616LL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 0x00010000000000000000LL, + + /* expect+1: ... integer 'unsigned long long' ... */ + 2147483647ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0x7fffffffULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 2147483648ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0x80000000ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 4294967295ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0xffffffffULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 4294967296ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0x0000000100000000ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 9223372036854775807ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0x7fffffffffffffffULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 9223372036854775808ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0x8000000000000000ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 18446744073709551615ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0xffffffffffffffffULL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 18446744073709551616ULL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 0x00010000000000000000ULL, +}; diff --git a/usr.bin/xlint/lint1/platform_ilp32_c99.c b/usr.bin/xlint/lint1/platform_ilp32_c99.c new file mode 100644 index 000000000000..94126a816eb2 --- /dev/null +++ b/usr.bin/xlint/lint1/platform_ilp32_c99.c @@ -0,0 +1,227 @@ +/* $NetBSD: platform_ilp32_c99.c,v 1.3 2024/01/28 08:26:07 rillig Exp $ */ +# 3 "platform_ilp32_c99.c" + +/* + * Tests that are specific to ILP32 platforms and the language level C99. + */ + +/* lint1-flags: -Sw -X 351 */ +/* lint1-only-if: ilp32 */ + +void *lex_integer[] = { + /* expect+1: ... integer 'int' ... */ + 2147483647, + /* expect+1: ... integer 'int' ... */ + 0x7fffffff, + /* expect+1: ... integer 'long long' ... */ + 2147483648, + /* expect+1: ... integer 'unsigned int' ... */ + 0x80000000, + /* expect+1: ... integer 'long long' ... */ + 4294967295, + /* expect+1: ... integer 'unsigned int' ... */ + 0xffffffff, + /* expect+1: ... integer 'long long' ... */ + 4294967296, + /* expect+1: ... integer 'long long' ... */ + 0x0000000100000000, + /* expect+1: ... integer 'long long' ... */ + 9223372036854775807, + /* expect+1: ... integer 'long long' ... */ + 0x7fffffffffffffff, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 9223372036854775808, + /* expect+1: ... integer 'unsigned long long' ... */ + 0x8000000000000000, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 18446744073709551615, + /* expect+1: ... integer 'unsigned long long' ... */ + 0xffffffffffffffff, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 18446744073709551616, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 0x00010000000000000000, + + /* expect+1: ... integer 'unsigned int' ... */ + 2147483647U, + /* expect+1: ... integer 'unsigned int' ... */ + 0x7fffffffU, + /* expect+1: ... integer 'unsigned int' ... */ + 2147483648U, + /* expect+1: ... integer 'unsigned int' ... */ + 0x80000000U, + /* expect+1: ... integer 'unsigned int' ... */ + 4294967295U, + /* expect+1: ... integer 'unsigned int' ... */ + 0xffffffffU, + /* expect+1: ... integer 'unsigned long long' ... */ + 4294967296U, + /* expect+1: ... integer 'unsigned long long' ... */ + 0x0000000100000000U, + /* expect+1: ... integer 'unsigned long long' ... */ + 9223372036854775807U, + /* expect+1: ... integer 'unsigned long long' ... */ + 0x7fffffffffffffffU, + /* expect+1: ... integer 'unsigned long long' ... */ + 9223372036854775808U, + /* expect+1: ... integer 'unsigned long long' ... */ + 0x8000000000000000U, + /* expect+1: ... integer 'unsigned long long' ... */ + 18446744073709551615U, + /* expect+1: ... integer 'unsigned long long' ... */ + 0xffffffffffffffffU, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 18446744073709551616U, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 0x00010000000000000000U, + + /* expect+1: ... integer 'long' ... */ + 2147483647L, + /* expect+1: ... integer 'long' ... */ + 0x7fffffffL, + /* expect+1: ... integer 'long long' ... */ + 2147483648L, + /* expect+1: ... integer 'unsigned long' ... */ + 0x80000000L, + /* expect+1: ... integer 'long long' ... */ + 4294967295L, + /* expect+1: ... integer 'unsigned long' ... */ + 0xffffffffL, + /* expect+1: ... integer 'long long' ... */ + 4294967296L, + /* expect+1: ... integer 'long long' ... */ + 0x0000000100000000L, + /* expect+1: ... integer 'long long' ... */ + 9223372036854775807L, + /* expect+1: ... integer 'long long' ... */ + 0x7fffffffffffffffL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 9223372036854775808L, + /* expect+1: ... integer 'unsigned long long' ... */ + 0x8000000000000000L, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 18446744073709551615L, + /* expect+1: ... integer 'unsigned long long' ... */ + 0xffffffffffffffffL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 18446744073709551616L, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 0x00010000000000000000L, + + /* expect+1: ... integer 'unsigned long' ... */ + 2147483647UL, + /* expect+1: ... integer 'unsigned long' ... */ + 0x7fffffffUL, + /* expect+1: ... integer 'unsigned long' ... */ + 2147483648UL, + /* expect+1: ... integer 'unsigned long' ... */ + 0x80000000UL, + /* expect+1: ... integer 'unsigned long' ... */ + 4294967295UL, + /* expect+1: ... integer 'unsigned long' ... */ + 0xffffffffUL, + /* expect+1: ... integer 'unsigned long long' ... */ + 4294967296UL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0x0000000100000000UL, + /* expect+1: ... integer 'unsigned long long' ... */ + 9223372036854775807UL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0x7fffffffffffffffUL, + /* expect+1: ... integer 'unsigned long long' ... */ + 9223372036854775808UL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0x8000000000000000UL, + /* expect+1: ... integer 'unsigned long long' ... */ + 18446744073709551615UL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0xffffffffffffffffUL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 18446744073709551616UL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 0x00010000000000000000UL, + + /* expect+1: ... integer 'long long' ... */ + 2147483647LL, + /* expect+1: ... integer 'long long' ... */ + 0x7fffffffLL, + /* expect+1: ... integer 'long long' ... */ + 2147483648LL, + /* expect+1: ... integer 'long long' ... */ + 0x80000000LL, + /* expect+1: ... integer 'long long' ... */ + 4294967295LL, + /* expect+1: ... integer 'long long' ... */ + 0xffffffffLL, + /* expect+1: ... integer 'long long' ... */ + 4294967296LL, + /* expect+1: ... integer 'long long' ... */ + 0x0000000100000000LL, + /* expect+1: ... integer 'long long' ... */ + 9223372036854775807LL, + /* expect+1: ... integer 'long long' ... */ + 0x7fffffffffffffffLL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 9223372036854775808LL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0x8000000000000000LL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 18446744073709551615LL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0xffffffffffffffffLL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 18446744073709551616LL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 0x00010000000000000000LL, + + /* expect+1: ... integer 'unsigned long long' ... */ + 2147483647ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0x7fffffffULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 2147483648ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0x80000000ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 4294967295ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0xffffffffULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 4294967296ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0x0000000100000000ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 9223372036854775807ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0x7fffffffffffffffULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 9223372036854775808ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0x8000000000000000ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 18446744073709551615ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0xffffffffffffffffULL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 18446744073709551616ULL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 0x00010000000000000000ULL, +}; diff --git a/usr.bin/xlint/lint1/platform_ilp32_trad.c b/usr.bin/xlint/lint1/platform_ilp32_trad.c new file mode 100644 index 000000000000..a8cc6fdafdc5 --- /dev/null +++ b/usr.bin/xlint/lint1/platform_ilp32_trad.c @@ -0,0 +1,130 @@ +/* $NetBSD: platform_ilp32_trad.c,v 1.4 2024/02/07 22:59:28 rillig Exp $ */ +# 3 "platform_ilp32_trad.c" + +/* + * Tests that are specific to ILP32 platforms and traditional C. + */ + +/* lint1-flags: -tw -X 351 */ +/* lint1-only-if: ilp32 */ + +void *lex_integer[] = { + /* expect+1: ... integer 'int' ... */ + 2147483647, + /* expect+1: ... integer 'int' ... */ + 0x7fffffff, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'long' ... */ + 2147483648, + /* expect+1: ... integer 'long' ... */ + 0x80000000, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'long' ... */ + 4294967295, + /* expect+1: ... integer 'long' ... */ + 0xffffffff, + /* expect+1: warning: integer constant out of range [252] */ + 4294967296, + /* expect+1: warning: integer constant out of range [252] */ + 0x0000000100000000, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'long' ... */ + 9223372036854775807, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'long' ... */ + 0x7fffffffffffffff, + /* expect+1: warning: integer constant out of range [252] */ + 9223372036854775808, + /* expect+1: warning: integer constant out of range [252] */ + 0x8000000000000000, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'long' ... */ + 18446744073709551615, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'long' ... */ + 0xffffffffffffffff, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'long' ... */ + 18446744073709551616, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'long' ... */ + 0x00010000000000000000, + + /* expect+1: ... integer 'long' ... */ + 2147483647L, + /* expect+1: ... integer 'long' ... */ + 0x7fffffffL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'long' ... */ + 2147483648L, + /* expect+1: ... integer 'long' ... */ + 0x80000000L, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'long' ... */ + 4294967295L, + /* expect+1: ... integer 'long' ... */ + 0xffffffffL, + /* expect+1: warning: integer constant out of range [252] */ + 4294967296L, + /* expect+1: warning: integer constant out of range [252] */ + 0x0000000100000000L, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'long' ... */ + 9223372036854775807L, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'long' ... */ + 0x7fffffffffffffffL, + /* expect+1: warning: integer constant out of range [252] */ + 9223372036854775808L, + /* expect+1: warning: integer constant out of range [252] */ + 0x8000000000000000L, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'long' ... */ + 18446744073709551615L, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'long' ... */ + 0xffffffffffffffffL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'long' ... */ + 18446744073709551616L, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'long' ... */ + 0x00010000000000000000L, + + /* expect+1: ... integer 'long long' ... */ + 2147483647LL, + /* expect+1: ... integer 'long long' ... */ + 0x7fffffffLL, + /* expect+1: ... integer 'long long' ... */ + 2147483648LL, + /* expect+1: ... integer 'long long' ... */ + 0x80000000LL, + /* expect+1: ... integer 'long long' ... */ + 4294967295LL, + /* expect+1: ... integer 'long long' ... */ + 0xffffffffLL, + /* expect+1: ... integer 'long long' ... */ + 4294967296LL, + /* expect+1: ... integer 'long long' ... */ + 0x0000000100000000LL, + /* expect+1: ... integer 'long long' ... */ + 9223372036854775807LL, + /* expect+1: ... integer 'long long' ... */ + 0x7fffffffffffffffLL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'long long' ... */ + 9223372036854775808LL, + /* expect+1: ... integer 'long long' ... */ + 0x8000000000000000LL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'long long' ... */ + 18446744073709551615LL, + /* expect+1: ... integer 'long long' ... */ + 0xffffffffffffffffLL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'long long' ... */ + 18446744073709551616LL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'long long' ... */ + 0x00010000000000000000LL, +}; diff --git a/usr.bin/xlint/lint1/platform_lp64_c90.c b/usr.bin/xlint/lint1/platform_lp64_c90.c new file mode 100644 index 000000000000..27868ccd8241 --- /dev/null +++ b/usr.bin/xlint/lint1/platform_lp64_c90.c @@ -0,0 +1,227 @@ +/* $NetBSD: platform_lp64_c90.c,v 1.3 2024/01/28 08:17:27 rillig Exp $ */ +# 3 "platform_lp64_c90.c" + +/* + * Tests that are specific to LP64 platforms and the language level C90. + */ + +/* lint1-flags: -sw -X 351 */ +/* lint1-only-if: lp64 */ + +void *lex_integer[] = { + /* expect+1: ... integer 'int' ... */ + 2147483647, + /* expect+1: ... integer 'int' ... */ + 0x7fffffff, + /* expect+1: ... integer 'long' ... */ + 2147483648, + /* expect+1: ... integer 'unsigned int' ... */ + 0x80000000, + /* expect+1: ... integer 'long' ... */ + 4294967295, + /* expect+1: ... integer 'unsigned int' ... */ + 0xffffffff, + /* expect+1: ... integer 'long' ... */ + 4294967296, + /* expect+1: ... integer 'long' ... */ + 0x0000000100000000, + /* expect+1: ... integer 'long' ... */ + 9223372036854775807, + /* expect+1: ... integer 'long' ... */ + 0x7fffffffffffffff, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 9223372036854775808, + /* expect+1: ... integer 'unsigned long' ... */ + 0x8000000000000000, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 18446744073709551615, + /* expect+1: ... integer 'unsigned long' ... */ + 0xffffffffffffffff, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 18446744073709551616, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 0x00010000000000000000, + + /* expect+1: ... integer 'unsigned int' ... */ + 2147483647U, + /* expect+1: ... integer 'unsigned int' ... */ + 0x7fffffffU, + /* expect+1: ... integer 'unsigned int' ... */ + 2147483648U, + /* expect+1: ... integer 'unsigned int' ... */ + 0x80000000U, + /* expect+1: ... integer 'unsigned int' ... */ + 4294967295U, + /* expect+1: ... integer 'unsigned int' ... */ + 0xffffffffU, + /* expect+1: ... integer 'unsigned long' ... */ + 4294967296U, + /* expect+1: ... integer 'unsigned long' ... */ + 0x0000000100000000U, + /* expect+1: ... integer 'unsigned long' ... */ + 9223372036854775807U, + /* expect+1: ... integer 'unsigned long' ... */ + 0x7fffffffffffffffU, + /* expect+1: ... integer 'unsigned long' ... */ + 9223372036854775808U, + /* expect+1: ... integer 'unsigned long' ... */ + 0x8000000000000000U, + /* expect+1: ... integer 'unsigned long' ... */ + 18446744073709551615U, + /* expect+1: ... integer 'unsigned long' ... */ + 0xffffffffffffffffU, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 18446744073709551616U, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 0x00010000000000000000U, + + /* expect+1: ... integer 'long' ... */ + 2147483647L, + /* expect+1: ... integer 'long' ... */ + 0x7fffffffL, + /* expect+1: ... integer 'long' ... */ + 2147483648L, + /* expect+1: ... integer 'long' ... */ + 0x80000000L, + /* expect+1: ... integer 'long' ... */ + 4294967295L, + /* expect+1: ... integer 'long' ... */ + 0xffffffffL, + /* expect+1: ... integer 'long' ... */ + 4294967296L, + /* expect+1: ... integer 'long' ... */ + 0x0000000100000000L, + /* expect+1: ... integer 'long' ... */ + 9223372036854775807L, + /* expect+1: ... integer 'long' ... */ + 0x7fffffffffffffffL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 9223372036854775808L, + /* expect+1: ... integer 'unsigned long' ... */ + 0x8000000000000000L, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 18446744073709551615L, + /* expect+1: ... integer 'unsigned long' ... */ + 0xffffffffffffffffL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 18446744073709551616L, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 0x00010000000000000000L, + + /* expect+1: ... integer 'unsigned long' ... */ + 2147483647UL, + /* expect+1: ... integer 'unsigned long' ... */ + 0x7fffffffUL, + /* expect+1: ... integer 'unsigned long' ... */ + 2147483648UL, + /* expect+1: ... integer 'unsigned long' ... */ + 0x80000000UL, + /* expect+1: ... integer 'unsigned long' ... */ + 4294967295UL, + /* expect+1: ... integer 'unsigned long' ... */ + 0xffffffffUL, + /* expect+1: ... integer 'unsigned long' ... */ + 4294967296UL, + /* expect+1: ... integer 'unsigned long' ... */ + 0x0000000100000000UL, + /* expect+1: ... integer 'unsigned long' ... */ + 9223372036854775807UL, + /* expect+1: ... integer 'unsigned long' ... */ + 0x7fffffffffffffffUL, + /* expect+1: ... integer 'unsigned long' ... */ + 9223372036854775808UL, + /* expect+1: ... integer 'unsigned long' ... */ + 0x8000000000000000UL, + /* expect+1: ... integer 'unsigned long' ... */ + 18446744073709551615UL, + /* expect+1: ... integer 'unsigned long' ... */ + 0xffffffffffffffffUL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 18446744073709551616UL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 0x00010000000000000000UL, + + /* expect+1: ... integer 'long long' ... */ + 2147483647LL, + /* expect+1: ... integer 'long long' ... */ + 0x7fffffffLL, + /* expect+1: ... integer 'long long' ... */ + 2147483648LL, + /* expect+1: ... integer 'long long' ... */ + 0x80000000LL, + /* expect+1: ... integer 'long long' ... */ + 4294967295LL, + /* expect+1: ... integer 'long long' ... */ + 0xffffffffLL, + /* expect+1: ... integer 'long long' ... */ + 4294967296LL, + /* expect+1: ... integer 'long long' ... */ + 0x0000000100000000LL, + /* expect+1: ... integer 'long long' ... */ + 9223372036854775807LL, + /* expect+1: ... integer 'long long' ... */ + 0x7fffffffffffffffLL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 9223372036854775808LL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0x8000000000000000LL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 18446744073709551615LL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0xffffffffffffffffLL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 18446744073709551616LL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 0x00010000000000000000LL, + + /* expect+1: ... integer 'unsigned long long' ... */ + 2147483647ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0x7fffffffULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 2147483648ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0x80000000ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 4294967295ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0xffffffffULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 4294967296ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0x0000000100000000ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 9223372036854775807ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0x7fffffffffffffffULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 9223372036854775808ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0x8000000000000000ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 18446744073709551615ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0xffffffffffffffffULL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 18446744073709551616ULL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 0x00010000000000000000ULL, +}; diff --git a/usr.bin/xlint/lint1/platform_lp64_c99.c b/usr.bin/xlint/lint1/platform_lp64_c99.c new file mode 100644 index 000000000000..007ad2a020c7 --- /dev/null +++ b/usr.bin/xlint/lint1/platform_lp64_c99.c @@ -0,0 +1,227 @@ +/* $NetBSD: platform_lp64_c99.c,v 1.3 2024/01/28 08:17:27 rillig Exp $ */ +# 3 "platform_lp64_c99.c" + +/* + * Tests that are specific to LP64 platforms and the language level C99. + */ + +/* lint1-flags: -Sw -X 351 */ +/* lint1-only-if: lp64 */ + +void *lex_integer[] = { + /* expect+1: ... integer 'int' ... */ + 2147483647, + /* expect+1: ... integer 'int' ... */ + 0x7fffffff, + /* expect+1: ... integer 'long' ... */ + 2147483648, + /* expect+1: ... integer 'unsigned int' ... */ + 0x80000000, + /* expect+1: ... integer 'long' ... */ + 4294967295, + /* expect+1: ... integer 'unsigned int' ... */ + 0xffffffff, + /* expect+1: ... integer 'long' ... */ + 4294967296, + /* expect+1: ... integer 'long' ... */ + 0x0000000100000000, + /* expect+1: ... integer 'long' ... */ + 9223372036854775807, + /* expect+1: ... integer 'long' ... */ + 0x7fffffffffffffff, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 9223372036854775808, + /* expect+1: ... integer 'unsigned long' ... */ + 0x8000000000000000, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 18446744073709551615, + /* expect+1: ... integer 'unsigned long' ... */ + 0xffffffffffffffff, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 18446744073709551616, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 0x00010000000000000000, + + /* expect+1: ... integer 'unsigned int' ... */ + 2147483647U, + /* expect+1: ... integer 'unsigned int' ... */ + 0x7fffffffU, + /* expect+1: ... integer 'unsigned int' ... */ + 2147483648U, + /* expect+1: ... integer 'unsigned int' ... */ + 0x80000000U, + /* expect+1: ... integer 'unsigned int' ... */ + 4294967295U, + /* expect+1: ... integer 'unsigned int' ... */ + 0xffffffffU, + /* expect+1: ... integer 'unsigned long' ... */ + 4294967296U, + /* expect+1: ... integer 'unsigned long' ... */ + 0x0000000100000000U, + /* expect+1: ... integer 'unsigned long' ... */ + 9223372036854775807U, + /* expect+1: ... integer 'unsigned long' ... */ + 0x7fffffffffffffffU, + /* expect+1: ... integer 'unsigned long' ... */ + 9223372036854775808U, + /* expect+1: ... integer 'unsigned long' ... */ + 0x8000000000000000U, + /* expect+1: ... integer 'unsigned long' ... */ + 18446744073709551615U, + /* expect+1: ... integer 'unsigned long' ... */ + 0xffffffffffffffffU, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 18446744073709551616U, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 0x00010000000000000000U, + + /* expect+1: ... integer 'long' ... */ + 2147483647L, + /* expect+1: ... integer 'long' ... */ + 0x7fffffffL, + /* expect+1: ... integer 'long' ... */ + 2147483648L, + /* expect+1: ... integer 'long' ... */ + 0x80000000L, + /* expect+1: ... integer 'long' ... */ + 4294967295L, + /* expect+1: ... integer 'long' ... */ + 0xffffffffL, + /* expect+1: ... integer 'long' ... */ + 4294967296L, + /* expect+1: ... integer 'long' ... */ + 0x0000000100000000L, + /* expect+1: ... integer 'long' ... */ + 9223372036854775807L, + /* expect+1: ... integer 'long' ... */ + 0x7fffffffffffffffL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 9223372036854775808L, + /* expect+1: ... integer 'unsigned long' ... */ + 0x8000000000000000L, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 18446744073709551615L, + /* expect+1: ... integer 'unsigned long' ... */ + 0xffffffffffffffffL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 18446744073709551616L, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 0x00010000000000000000L, + + /* expect+1: ... integer 'unsigned long' ... */ + 2147483647UL, + /* expect+1: ... integer 'unsigned long' ... */ + 0x7fffffffUL, + /* expect+1: ... integer 'unsigned long' ... */ + 2147483648UL, + /* expect+1: ... integer 'unsigned long' ... */ + 0x80000000UL, + /* expect+1: ... integer 'unsigned long' ... */ + 4294967295UL, + /* expect+1: ... integer 'unsigned long' ... */ + 0xffffffffUL, + /* expect+1: ... integer 'unsigned long' ... */ + 4294967296UL, + /* expect+1: ... integer 'unsigned long' ... */ + 0x0000000100000000UL, + /* expect+1: ... integer 'unsigned long' ... */ + 9223372036854775807UL, + /* expect+1: ... integer 'unsigned long' ... */ + 0x7fffffffffffffffUL, + /* expect+1: ... integer 'unsigned long' ... */ + 9223372036854775808UL, + /* expect+1: ... integer 'unsigned long' ... */ + 0x8000000000000000UL, + /* expect+1: ... integer 'unsigned long' ... */ + 18446744073709551615UL, + /* expect+1: ... integer 'unsigned long' ... */ + 0xffffffffffffffffUL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 18446744073709551616UL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long' ... */ + 0x00010000000000000000UL, + + /* expect+1: ... integer 'long long' ... */ + 2147483647LL, + /* expect+1: ... integer 'long long' ... */ + 0x7fffffffLL, + /* expect+1: ... integer 'long long' ... */ + 2147483648LL, + /* expect+1: ... integer 'long long' ... */ + 0x80000000LL, + /* expect+1: ... integer 'long long' ... */ + 4294967295LL, + /* expect+1: ... integer 'long long' ... */ + 0xffffffffLL, + /* expect+1: ... integer 'long long' ... */ + 4294967296LL, + /* expect+1: ... integer 'long long' ... */ + 0x0000000100000000LL, + /* expect+1: ... integer 'long long' ... */ + 9223372036854775807LL, + /* expect+1: ... integer 'long long' ... */ + 0x7fffffffffffffffLL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 9223372036854775808LL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0x8000000000000000LL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 18446744073709551615LL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0xffffffffffffffffLL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 18446744073709551616LL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 0x00010000000000000000LL, + + /* expect+1: ... integer 'unsigned long long' ... */ + 2147483647ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0x7fffffffULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 2147483648ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0x80000000ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 4294967295ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0xffffffffULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 4294967296ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0x0000000100000000ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 9223372036854775807ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0x7fffffffffffffffULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 9223372036854775808ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0x8000000000000000ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 18446744073709551615ULL, + /* expect+1: ... integer 'unsigned long long' ... */ + 0xffffffffffffffffULL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 18446744073709551616ULL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'unsigned long long' ... */ + 0x00010000000000000000ULL, +}; diff --git a/usr.bin/xlint/lint1/platform_lp64_trad.c b/usr.bin/xlint/lint1/platform_lp64_trad.c new file mode 100644 index 000000000000..a57db68ceb2e --- /dev/null +++ b/usr.bin/xlint/lint1/platform_lp64_trad.c @@ -0,0 +1,122 @@ +/* $NetBSD: platform_lp64_trad.c,v 1.4 2024/02/07 07:42:50 rillig Exp $ */ +# 3 "platform_lp64_trad.c" + +/* + * Tests that are specific to LP64 platforms and traditional C. + */ + +/* lint1-flags: -tw -X 351 */ +/* lint1-only-if: lp64 */ + +void *lex_integer[] = { + /* expect+1: ... integer 'int' ... */ + 2147483647, + /* expect+1: ... integer 'int' ... */ + 0x7fffffff, + /* expect+1: ... integer 'long' ... */ + 2147483648, + /* expect+1: ... integer 'long' ... */ + 0x80000000, + /* expect+1: ... integer 'long' ... */ + 4294967295, + /* expect+1: ... integer 'long' ... */ + 0xffffffff, + /* expect+1: ... integer 'long' ... */ + 4294967296, + /* expect+1: ... integer 'long' ... */ + 0x0000000100000000, + /* expect+1: ... integer 'long' ... */ + 9223372036854775807, + /* expect+1: ... integer 'long' ... */ + 0x7fffffffffffffff, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'long' ... */ + 9223372036854775808, + /* expect+1: ... integer 'long' ... */ + 0x8000000000000000, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'long' ... */ + 18446744073709551615, + /* expect+1: ... integer 'long' ... */ + 0xffffffffffffffff, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'long' ... */ + 18446744073709551616, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'long' ... */ + 0x00010000000000000000, + + /* expect+1: ... integer 'long' ... */ + 2147483647L, + /* expect+1: ... integer 'long' ... */ + 0x7fffffffL, + /* expect+1: ... integer 'long' ... */ + 2147483648L, + /* expect+1: ... integer 'long' ... */ + 0x80000000L, + /* expect+1: ... integer 'long' ... */ + 4294967295L, + /* expect+1: ... integer 'long' ... */ + 0xffffffffL, + /* expect+1: ... integer 'long' ... */ + 4294967296L, + /* expect+1: ... integer 'long' ... */ + 0x0000000100000000L, + /* expect+1: ... integer 'long' ... */ + 9223372036854775807L, + /* expect+1: ... integer 'long' ... */ + 0x7fffffffffffffffL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'long' ... */ + 9223372036854775808L, + /* expect+1: ... integer 'long' ... */ + 0x8000000000000000L, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'long' ... */ + 18446744073709551615L, + /* expect+1: ... integer 'long' ... */ + 0xffffffffffffffffL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'long' ... */ + 18446744073709551616L, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'long' ... */ + 0x00010000000000000000L, + + /* expect+1: ... integer 'long long' ... */ + 2147483647LL, + /* expect+1: ... integer 'long long' ... */ + 0x7fffffffLL, + /* expect+1: ... integer 'long long' ... */ + 2147483648LL, + /* expect+1: ... integer 'long long' ... */ + 0x80000000LL, + /* expect+1: ... integer 'long long' ... */ + 4294967295LL, + /* expect+1: ... integer 'long long' ... */ + 0xffffffffLL, + /* expect+1: ... integer 'long long' ... */ + 4294967296LL, + /* expect+1: ... integer 'long long' ... */ + 0x0000000100000000LL, + /* expect+1: ... integer 'long long' ... */ + 9223372036854775807LL, + /* expect+1: ... integer 'long long' ... */ + 0x7fffffffffffffffLL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'long long' ... */ + 9223372036854775808LL, + /* expect+1: ... integer 'long long' ... */ + 0x8000000000000000LL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'long long' ... */ + 18446744073709551615LL, + /* expect+1: ... integer 'long long' ... */ + 0xffffffffffffffffLL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'long long' ... */ + 18446744073709551616LL, + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: ... integer 'long long' ... */ + 0x00010000000000000000LL, +}; |
