Skip to content

Commit 5f62334

Browse files
committed
support GCC15
GCC 15 starts warning about non NUL-terminated string literals: chacha.c:44:31: error: initializer-string for array of ‘char’ truncates NUL terminator but destination lacks ‘nonstring’ attribute (17 chars into 16 available) [-Werror=unterminated-string-initialization] 44 | static const char sigma[16] = "expand 32-byte k"; | ^~~~~~~~~~~~~~~~~~
1 parent 4fe9018 commit 5f62334

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

chacha.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static const unsigned rounds = 8;
4141
a = PLUS(a, b); d = ROTATE(XOR(d, a), 8); \
4242
c = PLUS(c, d); b = ROTATE(XOR(b, c), 7);
4343

44-
static const char sigma[16] = "expand 32-byte k";
44+
static const char sigma[16] NONSTRING = "expand 32-byte k";
4545

4646
void chacha_keysetup(chacha_ctx *x, const u8 *k) {
4747
x->input[0] = U8TO32_LITTLE(sigma + 0);

util.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@
3232
#define STRINGIFY(s) #s
3333
#define ALIAS(f) __attribute__((alias(STRINGIFY(f))))
3434

35+
// supported since GCC 15
36+
#if defined __has_attribute
37+
# if __has_attribute (nonstring)
38+
# define NONSTRING __attribute__ ((nonstring))
39+
# else
40+
# define NONSTRING
41+
# endif
42+
#else
43+
# define NONSTRING
44+
#endif
45+
3546
typedef uint8_t u8;
3647
typedef uint16_t u16;
3748
typedef uint32_t u32;

0 commit comments

Comments
 (0)