Module Name: src Committed By: rillig Date: Sat Mar 9 16:47:10 UTC 2024
Modified Files: src/tests/usr.bin/xlint/lint1: platform_ilp32_int.c platform_ilp32_long.c platform_lp64.c Log Message: tests/lint: test check for out-of-bounds array index To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/platform_lp64.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c diff -u src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c:1.2 src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c:1.3 --- src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c:1.2 Tue Mar 28 14:44:35 2023 +++ src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c Sat Mar 9 16:47:09 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: platform_ilp32_int.c,v 1.2 2023/03/28 14:44:35 rillig Exp $ */ +/* $NetBSD: platform_ilp32_int.c,v 1.3 2024/03/09 16:47:09 rillig Exp $ */ # 3 "platform_ilp32_int.c" /* @@ -27,3 +27,25 @@ convert_between_int_and_long(void) u32 = ul32; ul32 = u32; } + +char ch; + +void +array_index(void) +{ + static char buf[20]; + + /* expect+1: warning: array subscript cannot be > 19: 2147483647 [168] */ + ch += buf[2147483647]; + /* expect+2: warning: conversion of 'long long' to 'int' is out of range [119] */ + /* expect+1: warning: array subscript cannot be negative: -2147483648 [167] */ + ch += buf[2147483648]; + /* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */ + /* expect+1: warning: array subscript cannot be negative: -2147483648 [167] */ + ch += buf[0x80000000]; + /* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */ + /* expect+1: warning: array subscript cannot be negative: -1 [167] */ + ch += buf[0xffffffff]; + /* expect+1: warning: array subscript cannot be negative: -1 [167] */ + ch += buf[0xffffffffffffffff]; +} Index: src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c diff -u src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c:1.4 src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c:1.5 --- src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c:1.4 Sat Jul 8 15:26:25 2023 +++ src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c Sat Mar 9 16:47:09 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: platform_ilp32_long.c,v 1.4 2023/07/08 15:26:25 rillig Exp $ */ +/* $NetBSD: platform_ilp32_long.c,v 1.5 2024/03/09 16:47:09 rillig Exp $ */ # 3 "platform_ilp32_long.c" /* @@ -36,3 +36,25 @@ convert_between_int_and_long(void) u32 = ul32; ul32 = u32; } + +char ch; + +void +array_index(void) +{ + static char buf[20]; + + /* expect+1: warning: array subscript cannot be > 19: 2147483647 [168] */ + ch += buf[2147483647]; + /* expect+2: warning: conversion of 'long long' to 'long' is out of range [119] */ + /* expect+1: warning: array subscript cannot be negative: -2147483648 [167] */ + ch += buf[2147483648]; + /* expect+2: warning: conversion of 'unsigned int' to 'long' is out of range [119] */ + /* expect+1: warning: array subscript cannot be negative: -2147483648 [167] */ + ch += buf[0x80000000]; + /* expect+2: warning: conversion of 'unsigned int' to 'long' is out of range [119] */ + /* expect+1: warning: array subscript cannot be negative: -1 [167] */ + ch += buf[0xffffffff]; + /* expect+1: warning: array subscript cannot be negative: -1 [167] */ + ch += buf[0xffffffffffffffff]; +} Index: src/tests/usr.bin/xlint/lint1/platform_lp64.c diff -u src/tests/usr.bin/xlint/lint1/platform_lp64.c:1.7 src/tests/usr.bin/xlint/lint1/platform_lp64.c:1.8 --- src/tests/usr.bin/xlint/lint1/platform_lp64.c:1.7 Sat Jul 8 12:45:43 2023 +++ src/tests/usr.bin/xlint/lint1/platform_lp64.c Sat Mar 9 16:47:09 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: platform_lp64.c,v 1.7 2023/07/08 12:45:43 rillig Exp $ */ +/* $NetBSD: platform_lp64.c,v 1.8 2024/03/09 16:47:09 rillig Exp $ */ # 3 "platform_lp64.c" /* @@ -44,3 +44,22 @@ convert_128(void) /* expect+1: warning: conversion from '__uint128_t' to 'unsigned int' may lose accuracy [132] */ u32 = u128; } + +char ch; + +void +array_index(void) +{ + static char buf[20]; + + /* expect+1: warning: array subscript cannot be > 19: 2147483647 [168] */ + ch += buf[2147483647]; + /* expect+1: warning: array subscript cannot be > 19: 2147483648 [168] */ + ch += buf[2147483648]; + /* expect+1: warning: array subscript cannot be > 19: 2147483648 [168] */ + ch += buf[0x80000000]; + /* expect+1: warning: array subscript cannot be > 19: 4294967295 [168] */ + ch += buf[0xffffffff]; + /* expect+1: warning: array subscript cannot be negative: -1 [167] */ + ch += buf[0xffffffffffffffff]; +}