From: Niels Möller Date: Tue, 12 May 2026 18:21:36 +0000 (+0200) Subject: Define and use NONSTRING attribute. X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fca809761e669289fa46059ed90aeb294dd74a1e;p=thirdparty%2Fnettle.git Define and use NONSTRING attribute. --- diff --git a/ChangeLog b/ChangeLog index b7979cf2..831788e2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2026-05-12 Niels Möller + Avoid gcc-15 warnings on missing NUL terminators. Based on patch + by Georg Sauthoff: + * aclocal.m4 (NETTLE_C_ATTRIBUTES): Define NONSTRING attribute. + * base16-encode.c (hex_digits): Declare as NONSTRING. + * base64-encode.c (base64_encode_table): Likewise. + * blowfish-bcrypt.c (radix64_encode_table): Likewise. + * tools/pkcs1-conv.c (pem_start_pattern, pem_end_pattern, pem_trailer_pattern): Likewise. + * nettle-types.h (_NETTLE_ATTRIBUTE_PURE): Change preprocessor conditionals to use __has_attribute. (_NETTLE_ATTRIBUTE_DEPRECATED): Deleted, no longer used. diff --git a/aclocal.m4 b/aclocal.m4 index 434e819d..602c5bad 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -49,6 +49,11 @@ AC_DEFUN([NETTLE_C_ATTRIBUTES], # else # define CONSTRUCTOR # endif +# if __has_attribute (__nonstring__) +# define NONSTRING __attribute__ ((__nonstring__)) +# else +# define NONSTRING +# endif # if __has_attribute (__noreturn__) # define NORETURN __attribute__ ((__noreturn__)) # else @@ -66,6 +71,7 @@ AC_DEFUN([NETTLE_C_ATTRIBUTES], # endif #else /* !_has_attribute */ # define CONSTRUCTOR +# define NONSTRING # define NORETURN # define PRINTF_STYLE(f, a) # define UNUSED diff --git a/base16-encode.c b/base16-encode.c index 9c7f0b1e..c6a4c6b9 100644 --- a/base16-encode.c +++ b/base16-encode.c @@ -39,7 +39,7 @@ static const uint8_t -hex_digits[16] = "0123456789abcdef"; +hex_digits[16] NONSTRING = "0123456789abcdef"; #define DIGIT(x) (hex_digits[(x) & 0xf]) diff --git a/base64-encode.c b/base64-encode.c index ee1ec149..6bb55782 100644 --- a/base64-encode.c +++ b/base64-encode.c @@ -83,7 +83,7 @@ encode_raw(const char *alphabet, assert(out == dst); } -static const char base64_encode_table[64] = +static const char base64_encode_table[64] NONSTRING = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789+/"; diff --git a/base64url-encode.c b/base64url-encode.c index d30044ea..2b78a800 100644 --- a/base64url-encode.c +++ b/base64url-encode.c @@ -38,7 +38,7 @@ void base64url_encode_init(struct base64_encode_ctx *ctx) { - static const char base64url_encode_table[64] = + static const char base64url_encode_table[64] NONSTRING = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789-_"; diff --git a/blowfish-bcrypt.c b/blowfish-bcrypt.c index 385503ac..0326f1ff 100644 --- a/blowfish-bcrypt.c +++ b/blowfish-bcrypt.c @@ -70,7 +70,7 @@ static const signed char radix64_decode_table[0x100] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, }; -static const char radix64_encode_table[64] = +static const char radix64_encode_table[64] NONSTRING = "./ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789"; diff --git a/tools/pkcs1-conv.c b/tools/pkcs1-conv.c index f6b044d2..68bb67d1 100644 --- a/tools/pkcs1-conv.c +++ b/tools/pkcs1-conv.c @@ -117,13 +117,13 @@ read_file(struct nettle_buffer *buffer, FILE *f) } static const uint8_t -pem_start_pattern[11] = "-----BEGIN "; +pem_start_pattern[11] NONSTRING = "-----BEGIN "; static const uint8_t -pem_end_pattern[9] = "-----END "; +pem_end_pattern[9] NONSTRING = "-----END "; static const uint8_t -pem_trailer_pattern[5] = "-----"; +pem_trailer_pattern[5] NONSTRING = "-----"; static const char pem_ws[33] = {