Module Name: src Committed By: rillig Date: Tue Dec 21 22:21:11 UTC 2021
Modified Files: src/tests/usr.bin/xlint/lint1: d_init_array_using_string.c d_init_array_using_string.exp msg_187.c msg_187.exp src/usr.bin/xlint/lint1: err.c init.c Log Message: lint: reword message 187 about too long string literal for initializer The previous message was imprecise in that it didn't distinguish between non-terminating and terminating null bytes. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 \ src/tests/usr.bin/xlint/lint1/d_init_array_using_string.c \ src/tests/usr.bin/xlint/lint1/d_init_array_using_string.exp cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_187.c \ src/tests/usr.bin/xlint/lint1/msg_187.exp cvs rdiff -u -r1.148 -r1.149 src/usr.bin/xlint/lint1/err.c cvs rdiff -u -r1.227 -r1.228 src/usr.bin/xlint/lint1/init.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/d_init_array_using_string.c diff -u src/tests/usr.bin/xlint/lint1/d_init_array_using_string.c:1.6 src/tests/usr.bin/xlint/lint1/d_init_array_using_string.c:1.7 --- src/tests/usr.bin/xlint/lint1/d_init_array_using_string.c:1.6 Fri Sep 10 20:02:51 2021 +++ src/tests/usr.bin/xlint/lint1/d_init_array_using_string.c Tue Dec 21 22:21:11 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: d_init_array_using_string.c,v 1.6 2021/09/10 20:02:51 rillig Exp $ */ +/* $NetBSD: d_init_array_using_string.c,v 1.7 2021/12/21 22:21:11 rillig Exp $ */ # 3 "d_init_array_using_string.c" /* @@ -70,8 +70,10 @@ test_array_initialization_in_struct(void }; struct cs_ws too_many_characters = { - "0123456789X", /* expect: non-null byte ignored */ - L"0123456789X", /* expect: non-null byte ignored */ + /* expect+1: warning: string literal too long (11) for target array (10) */ + "0123456789X", + /* expect+1: warning: string literal too long (11) for target array (10) */ + L"0123456789X", }; struct cs_ws extra_braces = { Index: src/tests/usr.bin/xlint/lint1/d_init_array_using_string.exp diff -u src/tests/usr.bin/xlint/lint1/d_init_array_using_string.exp:1.6 src/tests/usr.bin/xlint/lint1/d_init_array_using_string.exp:1.7 --- src/tests/usr.bin/xlint/lint1/d_init_array_using_string.exp:1.6 Sat Aug 14 13:00:55 2021 +++ src/tests/usr.bin/xlint/lint1/d_init_array_using_string.exp Tue Dec 21 22:21:11 2021 @@ -4,5 +4,5 @@ d_init_array_using_string.c(37): warning d_init_array_using_string.c(39): warning: illegal combination of 'pointer to const int' and 'pointer to char', op 'init' [124] d_init_array_using_string.c(63): error: cannot initialize 'array[10] of const char' from 'pointer to int' [185] d_init_array_using_string.c(64): error: cannot initialize 'array[10] of const int' from 'pointer to char' [185] -d_init_array_using_string.c(73): warning: non-null byte ignored in string initializer [187] -d_init_array_using_string.c(74): warning: non-null byte ignored in string initializer [187] +d_init_array_using_string.c(74): warning: string literal too long (11) for target array (10) [187] +d_init_array_using_string.c(76): warning: string literal too long (11) for target array (10) [187] Index: src/tests/usr.bin/xlint/lint1/msg_187.c diff -u src/tests/usr.bin/xlint/lint1/msg_187.c:1.3 src/tests/usr.bin/xlint/lint1/msg_187.c:1.4 --- src/tests/usr.bin/xlint/lint1/msg_187.c:1.3 Thu Sep 2 18:20:00 2021 +++ src/tests/usr.bin/xlint/lint1/msg_187.c Tue Dec 21 22:21:11 2021 @@ -1,25 +1,22 @@ -/* $NetBSD: msg_187.c,v 1.3 2021/09/02 18:20:00 rillig Exp $ */ +/* $NetBSD: msg_187.c,v 1.4 2021/12/21 22:21:11 rillig Exp $ */ # 3 "msg_187.c" -// Test for message: non-null byte ignored in string initializer [187] +// Test for message: string literal too long (%lu) for target array (%lu) [187] char auto_msg[] = "the string length is determined automatically"; +/* The terminating null byte is not copied to the array. */ char large_enough[10] = "0123456789"; -/* expect+1: warning: non-null byte ignored in string initializer [187] */ +/* expect+1: warning: string literal too long (10) for target array (9) [187] */ char too_small[9] = "0123456789"; char x0[3] = "x\0"; char xx0[3] = "xx\0"; -/* expect+1: warning: non-null byte ignored in string initializer [187] */ +/* expect+1: warning: string literal too long (4) for target array (3) [187] */ char xxx0[3] = "012\0"; -/* - * The warning is not entirely correct. It is a non-terminating byte that - * is ignored. - */ -/* expect+1: warning: non-null byte ignored in string initializer [187] */ +/* expect+1: warning: string literal too long (4) for target array (3) [187] */ char xx00[3] = "01\0\0"; Index: src/tests/usr.bin/xlint/lint1/msg_187.exp diff -u src/tests/usr.bin/xlint/lint1/msg_187.exp:1.3 src/tests/usr.bin/xlint/lint1/msg_187.exp:1.4 --- src/tests/usr.bin/xlint/lint1/msg_187.exp:1.3 Thu Sep 2 18:20:00 2021 +++ src/tests/usr.bin/xlint/lint1/msg_187.exp Tue Dec 21 22:21:11 2021 @@ -1,3 +1,3 @@ -msg_187.c(11): warning: non-null byte ignored in string initializer [187] -msg_187.c(18): warning: non-null byte ignored in string initializer [187] -msg_187.c(25): warning: non-null byte ignored in string initializer [187] +msg_187.c(12): warning: string literal too long (10) for target array (9) [187] +msg_187.c(19): warning: string literal too long (4) for target array (3) [187] +msg_187.c(22): warning: string literal too long (4) for target array (3) [187] Index: src/usr.bin/xlint/lint1/err.c diff -u src/usr.bin/xlint/lint1/err.c:1.148 src/usr.bin/xlint/lint1/err.c:1.149 --- src/usr.bin/xlint/lint1/err.c:1.148 Sat Dec 4 00:01:24 2021 +++ src/usr.bin/xlint/lint1/err.c Tue Dec 21 22:21:11 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: err.c,v 1.148 2021/12/04 00:01:24 rillig Exp $ */ +/* $NetBSD: err.c,v 1.149 2021/12/21 22:21:11 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: err.c,v 1.148 2021/12/04 00:01:24 rillig Exp $"); +__RCSID("$NetBSD: err.c,v 1.149 2021/12/21 22:21:11 rillig Exp $"); #endif #include <sys/types.h> @@ -241,7 +241,7 @@ const char *const msgs[] = { "illegal combination of '%s' and '%s'", /* 184 */ "cannot initialize '%s' from '%s'", /* 185 */ "bit-field initialization is illegal in traditional C", /* 186 */ - "non-null byte ignored in string initializer", /* 187 */ + "string literal too long (%lu) for target array (%lu)", /* 187 */ "no automatic aggregate initialization in traditional C", /* 188 */ "", /* no longer used */ /* 189 */ "empty array declaration: %s", /* 190 */ Index: src/usr.bin/xlint/lint1/init.c diff -u src/usr.bin/xlint/lint1/init.c:1.227 src/usr.bin/xlint/lint1/init.c:1.228 --- src/usr.bin/xlint/lint1/init.c:1.227 Tue Dec 21 21:42:21 2021 +++ src/usr.bin/xlint/lint1/init.c Tue Dec 21 22:21:11 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: init.c,v 1.227 2021/12/21 21:42:21 rillig Exp $ */ +/* $NetBSD: init.c,v 1.228 2021/12/21 22:21:11 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -38,7 +38,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: init.c,v 1.227 2021/12/21 21:42:21 rillig Exp $"); +__RCSID("$NetBSD: init.c,v 1.228 2021/12/21 22:21:11 rillig Exp $"); #endif #include <stdlib.h> @@ -858,8 +858,9 @@ initialization_init_array_from_string(in return false; if (!tp->t_incomplete_array && tp->t_dim < (int)strg->st_len) { - /* non-null byte ignored in string initializer */ - warning(187); + /* string literal too long (%lu) for target array (%lu) */ + warning(187, + (unsigned long)strg->st_len, (unsigned long)tp->t_dim); } if (tp == in->in_sym->s_type && tp->t_incomplete_array) {