Skip to content

Commit b207d09

Browse files
committed
Suppress gcc 15 unterminated-string-initialization warnings
1 parent 37db51b commit b207d09

12 files changed

Lines changed: 59 additions & 8 deletions

File tree

common.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9992,6 +9992,7 @@ marshal.$(OBJEXT): {$(VPATH)}internal/attr/nodiscard.h
99929992
marshal.$(OBJEXT): {$(VPATH)}internal/attr/noexcept.h
99939993
marshal.$(OBJEXT): {$(VPATH)}internal/attr/noinline.h
99949994
marshal.$(OBJEXT): {$(VPATH)}internal/attr/nonnull.h
9995+
marshal.$(OBJEXT): {$(VPATH)}internal/attr/nonstring.h
99959996
marshal.$(OBJEXT): {$(VPATH)}internal/attr/noreturn.h
99969997
marshal.$(OBJEXT): {$(VPATH)}internal/attr/packed_struct.h
99979998
marshal.$(OBJEXT): {$(VPATH)}internal/attr/pure.h
@@ -10613,6 +10614,7 @@ miniinit.$(OBJEXT): {$(VPATH)}internal/attr/nodiscard.h
1061310614
miniinit.$(OBJEXT): {$(VPATH)}internal/attr/noexcept.h
1061410615
miniinit.$(OBJEXT): {$(VPATH)}internal/attr/noinline.h
1061510616
miniinit.$(OBJEXT): {$(VPATH)}internal/attr/nonnull.h
10617+
miniinit.$(OBJEXT): {$(VPATH)}internal/attr/nonstring.h
1061610618
miniinit.$(OBJEXT): {$(VPATH)}internal/attr/noreturn.h
1061710619
miniinit.$(OBJEXT): {$(VPATH)}internal/attr/packed_struct.h
1061810620
miniinit.$(OBJEXT): {$(VPATH)}internal/attr/pure.h
@@ -16937,6 +16939,7 @@ signal.$(OBJEXT): {$(VPATH)}internal/attr/nodiscard.h
1693716939
signal.$(OBJEXT): {$(VPATH)}internal/attr/noexcept.h
1693816940
signal.$(OBJEXT): {$(VPATH)}internal/attr/noinline.h
1693916941
signal.$(OBJEXT): {$(VPATH)}internal/attr/nonnull.h
16942+
signal.$(OBJEXT): {$(VPATH)}internal/attr/nonstring.h
1694016943
signal.$(OBJEXT): {$(VPATH)}internal/attr/noreturn.h
1694116944
signal.$(OBJEXT): {$(VPATH)}internal/attr/packed_struct.h
1694216945
signal.$(OBJEXT): {$(VPATH)}internal/attr/pure.h
@@ -17705,6 +17708,7 @@ string.$(OBJEXT): {$(VPATH)}internal/attr/nodiscard.h
1770517708
string.$(OBJEXT): {$(VPATH)}internal/attr/noexcept.h
1770617709
string.$(OBJEXT): {$(VPATH)}internal/attr/noinline.h
1770717710
string.$(OBJEXT): {$(VPATH)}internal/attr/nonnull.h
17711+
string.$(OBJEXT): {$(VPATH)}internal/attr/nonstring.h
1770817712
string.$(OBJEXT): {$(VPATH)}internal/attr/noreturn.h
1770917713
string.$(OBJEXT): {$(VPATH)}internal/attr/packed_struct.h
1771017714
string.$(OBJEXT): {$(VPATH)}internal/attr/pure.h
@@ -18170,6 +18174,7 @@ symbol.$(OBJEXT): {$(VPATH)}internal/attr/nodiscard.h
1817018174
symbol.$(OBJEXT): {$(VPATH)}internal/attr/noexcept.h
1817118175
symbol.$(OBJEXT): {$(VPATH)}internal/attr/noinline.h
1817218176
symbol.$(OBJEXT): {$(VPATH)}internal/attr/nonnull.h
18177+
symbol.$(OBJEXT): {$(VPATH)}internal/attr/nonstring.h
1817318178
symbol.$(OBJEXT): {$(VPATH)}internal/attr/noreturn.h
1817418179
symbol.$(OBJEXT): {$(VPATH)}internal/attr/packed_struct.h
1817518180
symbol.$(OBJEXT): {$(VPATH)}internal/attr/pure.h

enc/depend

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7016,6 +7016,7 @@ enc/trans/iso2022.$(OBJEXT): internal/attr/nodiscard.h
70167016
enc/trans/iso2022.$(OBJEXT): internal/attr/noexcept.h
70177017
enc/trans/iso2022.$(OBJEXT): internal/attr/noinline.h
70187018
enc/trans/iso2022.$(OBJEXT): internal/attr/nonnull.h
7019+
enc/trans/iso2022.$(OBJEXT): internal/attr/nonstring.h
70197020
enc/trans/iso2022.$(OBJEXT): internal/attr/noreturn.h
70207021
enc/trans/iso2022.$(OBJEXT): internal/attr/packed_struct.h
70217022
enc/trans/iso2022.$(OBJEXT): internal/attr/pure.h

enc/trans/iso2022.trans

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "transcode_data.h"
2+
#include "ruby/internal/attr/nonstring.h"
23

34
<%
45
map = {
@@ -436,7 +437,7 @@ rb_cp50221_encoder = {
436437

437438
/* JIS0201 to JIS0208 conversion table */
438439
enum {tbl0208_num = 0xDF - 0xA1 + 1};
439-
static const char tbl0208[tbl0208_num][2] = {
440+
RBIMPL_ATTR_NONSTRING() static const char tbl0208[tbl0208_num][2] = {
440441
"\x21\x23", "\x21\x56", "\x21\x57", "\x21\x22",
441442
"\x21\x26", "\x25\x72", "\x25\x21", "\x25\x23",
442443
"\x25\x25", "\x25\x27", "\x25\x29", "\x25\x63",
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#ifndef RBIMPL_ATTR_NONSTRING_H /*-*-C++-*-vi:se ft=cpp:*/
2+
#define RBIMPL_ATTR_NONSTRING_H
3+
/**
4+
* @file
5+
* @author Ruby developers <ruby-core@ruby-lang.org>
6+
* @copyright This file is a part of the programming language Ruby.
7+
* Permission is hereby granted, to either redistribute and/or
8+
* modify this file, provided that the conditions mentioned in the
9+
* file COPYING are met. Consult the file for details.
10+
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
11+
* implementation details. Don't take them as canon. They could
12+
* rapidly appear then vanish. The name (path) of this header file
13+
* is also an implementation detail. Do not expect it to persist
14+
* at the place it is now. Developers are free to move it anywhere
15+
* anytime at will.
16+
* @note To ruby-core: remember that this header can be possibly
17+
* recursively included from extension libraries written in C++.
18+
* Do not expect for instance `__VA_ARGS__` is always available.
19+
* We assume C99 for ruby itself but we don't assume languages of
20+
* extension libraries. They could be written in C++98.
21+
* @brief Defines #RBIMPL_ATTR_NONSTRING.
22+
*/
23+
#include "ruby/internal/has/attribute.h"
24+
25+
/** Wraps (or simulates) `__attribute__((nonstring))` */
26+
#if RBIMPL_HAS_ATTRIBUTE(nonstring)
27+
# define RBIMPL_ATTR_NONSTRING() __attribute__((nonstring))
28+
#else
29+
# define RBIMPL_ATTR_NONSTRING() /* void */
30+
#endif
31+
32+
#endif /* RBIMPL_ATTR_NONSTRING_H */

marshal.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "ruby/util.h"
4141
#include "builtin.h"
4242
#include "shape.h"
43+
#include "ruby/internal/attr/nonstring.h"
4344

4445
#define BITSPERSHORT (2*CHAR_BIT)
4546
#define SHORTMASK ((1<<BITSPERSHORT)-1)
@@ -1515,7 +1516,7 @@ name_equal(const char *name, size_t nlen, const char *p, long l)
15151516
static int
15161517
sym2encidx(VALUE sym, VALUE val)
15171518
{
1518-
static const char name_encoding[8] = "encoding";
1519+
RBIMPL_ATTR_NONSTRING() static const char name_encoding[8] = "encoding";
15191520
const char *p;
15201521
long l;
15211522
if (rb_enc_get_index(sym) != ENCINDEX_US_ASCII) return -1;

regenc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ typedef struct {
118118

119119
typedef struct {
120120
short int len;
121+
#if defined(__has_attribute) && __has_attribute(nonstring)
122+
__attribute__((nonstring))
123+
#endif
121124
const UChar name[6];
122125
int ctype;
123126
} PosixBracketEntryType;

signal.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "ruby_atomic.h"
4646
#include "vm_core.h"
4747
#include "ractor_core.h"
48+
#include "ruby/internal/attr/nonstring.h"
4849

4950
#ifdef NEED_RUBY_ATOMIC_OPS
5051
rb_atomic_t
@@ -976,7 +977,7 @@ check_reserved_signal_(const char *name, size_t name_len, int signo)
976977
if (prev) {
977978
ssize_t RB_UNUSED_VAR(err);
978979
static const int stderr_fd = 2;
979-
#define NOZ(name, str) name[sizeof(str)-1] = str
980+
#define NOZ(name, str) RBIMPL_ATTR_NONSTRING() name[sizeof(str)-1] = str
980981
static const char NOZ(msg1, " received in ");
981982
static const char NOZ(msg2, " handler\n");
982983

siphash.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ xor64_to(uint64_t *v, const uint64_t s)
140140
#endif
141141

142142
static const union {
143+
#if defined(__has_attribute) && __has_attribute(nonstring)
144+
__attribute__((nonstring))
145+
#endif
143146
char bin[32];
144147
uint64_t u64[4];
145148
} sip_init_state_bin = {"uespemos""modnarod""arenegyl""setybdet"};

string.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "ruby/util.h"
4747
#include "ruby_assert.h"
4848
#include "vm_sync.h"
49+
#include "ruby/internal/attr/nonstring.h"
4950

5051
#if defined HAVE_CRYPT_R
5152
# if defined HAVE_CRYPT_H
@@ -11971,7 +11972,7 @@ enc_str_scrub(rb_encoding *enc, VALUE str, VALUE repl, int cr)
1197111972
encidx = rb_enc_to_index(enc);
1197211973

1197311974
#define DEFAULT_REPLACE_CHAR(str) do { \
11974-
static const char replace[sizeof(str)-1] = str; \
11975+
RBIMPL_ATTR_NONSTRING() static const char replace[sizeof(str)-1] = str; \
1197511976
rep = replace; replen = (int)sizeof(replace); \
1197611977
} while (0)
1197711978

symbol.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "symbol.h"
2323
#include "vm_sync.h"
2424
#include "builtin.h"
25+
#include "ruby/internal/attr/nonstring.h"
2526

2627
#if defined(USE_SYMBOL_GC) && !(USE_SYMBOL_GC+0)
2728
# undef USE_SYMBOL_GC
@@ -171,7 +172,7 @@ rb_id_attrset(ID id)
171172

172173
/* make new symbol and ID */
173174
if (!(str = lookup_id_str(id))) {
174-
static const char id_types[][8] = {
175+
RBIMPL_ATTR_NONSTRING() static const char id_types[][8] = {
175176
"local",
176177
"instance",
177178
"invalid",

0 commit comments

Comments
 (0)