Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 02 Jan 2026 20:52:28 +0000
From:      Dimitry Andric <dim@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 3015ca9407d1 - stable/13 - sh: avoid warnings about too-long initializer strings
Message-ID:  <6958300c.a8bf.bb890a2@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch stable/13 has been updated by dim:

URL: https://cgit.FreeBSD.org/src/commit/?id=3015ca9407d14876b1b6e8babc5b94acd939af68

commit 3015ca9407d14876b1b6e8babc5b94acd939af68
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2025-12-25 20:13:48 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2026-01-02 20:49:46 +0000

    sh: avoid warnings about too-long initializer strings
    
    Mark `optletter` and `t_op::op_text` as `__non_string`, to avoid
    warnings from clang 21 similar to:
    
        bin/sh/options.h:77:36: error: initializer-string for character array is too long, array size is 19 but initializer has size 20 (including the null terminating character); did you mean to use the 'nonstring' attribute? [-Werror,-Wunterminated-string-initialization]
           77 | const char optletter[NSHORTOPTS] = "efIimnsxvVECabupTPh";
              |                                    ^~~~~~~~~~~~~~~~~~~~~
        bin/test/test.c:153:3: error: initializer-string for character array is too long, array size is 2 but initializer has size 3 (including the null terminating character); did you mean to use the 'nonstring' attribute? [-Werror,-Wunterminated-string-initialization]
          153 |         {"==",  STREQ},
              |          ^~~~
    
    MFC after:      3 days
    Reviewed by:    jilles
    Differential Revision: https://reviews.freebsd.org/D54362
    
    (cherry picked from commit e6546807f4c1a8a6a6fa53fceab7b8c80e3ed802)
---
 bin/sh/options.h | 2 +-
 bin/test/test.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/bin/sh/options.h b/bin/sh/options.h
index cd28baeeed6d..94fba049d2d4 100644
--- a/bin/sh/options.h
+++ b/bin/sh/options.h
@@ -75,7 +75,7 @@ extern char optval[NOPTS];
 extern const char optletter[NSHORTOPTS];
 #ifdef DEFINE_OPTIONS
 char optval[NOPTS];
-const char optletter[NSHORTOPTS] = "efIimnsxvVECabupTPh";
+const char optletter[NSHORTOPTS] __nonstring = "efIimnsxvVECabupTPh";
 static const unsigned char optname[] =
 	"\007errexit"
 	"\006noglob"
diff --git a/bin/test/test.c b/bin/test/test.c
index 1cb3eca8fe13..b8f6845c221f 100644
--- a/bin/test/test.c
+++ b/bin/test/test.c
@@ -117,7 +117,7 @@ enum token {
 #define TOKEN_TYPE(token) ((token) & 0xff00)
 
 static const struct t_op {
-	char op_text[2];
+	char op_text[2] __nonstring;
 	short op_num;
 } ops1[] = {
 	{"=",	STREQ},


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6958300c.a8bf.bb890a2>