Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 lint: reword message 187 about too long ...



details:   https://anonhg.NetBSD.org/src/rev/73d2491b5b28
branches:  trunk
changeset: 1029112:73d2491b5b28
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Dec 21 22:21:11 2021 +0000

description:
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.

diffstat:

 tests/usr.bin/xlint/lint1/d_init_array_using_string.c   |   8 +++++---
 tests/usr.bin/xlint/lint1/d_init_array_using_string.exp |   4 ++--
 tests/usr.bin/xlint/lint1/msg_187.c                     |  15 ++++++---------
 tests/usr.bin/xlint/lint1/msg_187.exp                   |   6 +++---
 usr.bin/xlint/lint1/err.c                               |   6 +++---
 usr.bin/xlint/lint1/init.c                              |   9 +++++----
 6 files changed, 24 insertions(+), 24 deletions(-)

diffs (135 lines):

diff -r 602b7594fe1a -r 73d2491b5b28 tests/usr.bin/xlint/lint1/d_init_array_using_string.c
--- a/tests/usr.bin/xlint/lint1/d_init_array_using_string.c     Tue Dec 21 21:42:21 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_init_array_using_string.c     Tue Dec 21 22:21:11 2021 +0000
@@ -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 @@
        };
 
        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 = {
diff -r 602b7594fe1a -r 73d2491b5b28 tests/usr.bin/xlint/lint1/d_init_array_using_string.exp
--- a/tests/usr.bin/xlint/lint1/d_init_array_using_string.exp   Tue Dec 21 21:42:21 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_init_array_using_string.exp   Tue Dec 21 22:21:11 2021 +0000
@@ -4,5 +4,5 @@
 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]
diff -r 602b7594fe1a -r 73d2491b5b28 tests/usr.bin/xlint/lint1/msg_187.c
--- a/tests/usr.bin/xlint/lint1/msg_187.c       Tue Dec 21 21:42:21 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_187.c       Tue Dec 21 22:21:11 2021 +0000
@@ -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";
diff -r 602b7594fe1a -r 73d2491b5b28 tests/usr.bin/xlint/lint1/msg_187.exp
--- a/tests/usr.bin/xlint/lint1/msg_187.exp     Tue Dec 21 21:42:21 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_187.exp     Tue Dec 21 22:21:11 2021 +0000
@@ -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]
diff -r 602b7594fe1a -r 73d2491b5b28 usr.bin/xlint/lint1/err.c
--- a/usr.bin/xlint/lint1/err.c Tue Dec 21 21:42:21 2021 +0000
+++ b/usr.bin/xlint/lint1/err.c Tue Dec 21 22:21:11 2021 +0000
@@ -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 @@
        "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 */
diff -r 602b7594fe1a -r 73d2491b5b28 usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c        Tue Dec 21 21:42:21 2021 +0000
+++ b/usr.bin/xlint/lint1/init.c        Tue Dec 21 22:21:11 2021 +0000
@@ -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 @@
                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) {



Home | Main Index | Thread Index | Old Index