nettle@gms.tf writes:
This fixes -Wunterminated-string-initialization warnings with gcc 15.2.1.
I've merged more or less these changes to the use-has_attribute branch. I replaced the old configure-time attribute check with a macro that just inserts __has_attribute conditionals in config.h.in.
I'm about to merge this to master, maybe you or someone else wants to have a look at the changes? In patch form below.
Regards, /Niels
diff --git a/ChangeLog b/ChangeLog index 274c5392..831788e2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,31 @@ +2026-05-12 Niels Möller nisse@lysator.liu.se + + 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. + +2026-05-11 Niels Möller nisse@lysator.liu.se + + * aclocal.m4 (LSH_GCC_ATTRIBUTES): Delete macro, based on + AC_COMPILE_IF_ELSE, and config.h define HAVE_GCC_ATTRIBUTE. + Replaced by... + (NETTLE_C_ATTRIBUTES): Simpler macro, just adding code to config.h + to define CONSTRUCTOR, NORETURN, PRINTF_STYLE and UNUSED, when + corresponding attributes are supported according to + __has_attribute. The __has_attribute test was introduced in clang + and gcc a decade ago. + * configure.ac: Use NETTLE_C_ATTRIBUTES. + * fat-setup.h: Remove local definition of CONSTRUCTOR. Also drop + support for using #pragma init(...) with Sun compilers. + 2026-05-07 Niels Möller nisse@lysator.liu.se
Add support for sntrup761. diff --git a/aclocal.m4 b/aclocal.m4 index 73bf0cfb..602c5bad 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -38,37 +38,40 @@ AC_CACHE_VAL(lsh_cv_sys_ccpic,[ CCPIC="$lsh_cv_sys_ccpic" AC_MSG_RESULT($CCPIC)])
-dnl LSH_GCC_ATTRIBUTES -dnl Check for gcc's __attribute__ construction - -AC_DEFUN([LSH_GCC_ATTRIBUTES], -[AC_CACHE_CHECK(for __attribute__, - lsh_cv_c_attribute, -[ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ -#include <stdlib.h> - -static void foo(void) __attribute__ ((noreturn)); - -static void __attribute__ ((noreturn)) -foo(void) -{ - exit(1); -} -]], [[]])], - [lsh_cv_c_attribute=yes], - [lsh_cv_c_attribute=no])]) - -AH_TEMPLATE([HAVE_GCC_ATTRIBUTE], [Define if the compiler understands __attribute__]) -if test "x$lsh_cv_c_attribute" = "xyes"; then - AC_DEFINE(HAVE_GCC_ATTRIBUTE) -fi - -AH_BOTTOM( -[#if __GNUC__ && HAVE_GCC_ATTRIBUTE -# define NORETURN __attribute__ ((__noreturn__)) -# define PRINTF_STYLE(f, a) __attribute__ ((__format__ (__printf__, f, a))) -# define UNUSED __attribute__ ((__unused__)) -#else +dnl NETTLE_C_ATTRIBUTES +dnl Add code to config.h checking __has_attribute for the attributes +dnl we use. +AC_DEFUN([NETTLE_C_ATTRIBUTES], +[AH_BOTTOM([ +#ifdef __has_attribute +# if __has_attribute (__constructor__) +# define CONSTRUCTOR __attribute__ ((__constructor__)) +# 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 +# define NORETURN +# endif +# if __has_attribute (__format__) +# define PRINTF_STYLE(f, a) __attribute__ ((__format__ (__printf__, f, a))) +# else +# define PRINTF_STYLE(f, a) +# endif +# if __has_attribute (__unused__) +# define UNUSED __attribute__ ((__unused__)) +# else +# define UNUSED +# 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/configure.ac b/configure.ac index af017d81..c49462cb 100644 --- a/configure.ac +++ b/configure.ac @@ -215,7 +215,7 @@ if test "x$nettle_cv_c_builtin_bswap64" = "xyes" ; then AC_DEFINE(HAVE_BUILTIN_BSWAP64) fi
-LSH_GCC_ATTRIBUTES +NETTLE_C_ATTRIBUTES
# Check for file locking. We (AC_PROG_CC?) have already checked for # sys/types.h and unistd.h. diff --git a/fat-setup.h b/fat-setup.h index 37a600a8..3c53db41 100644 --- a/fat-setup.h +++ b/fat-setup.h @@ -68,15 +68,6 @@ time. */
-#if HAVE_GCC_ATTRIBUTE -# define CONSTRUCTOR __attribute__ ((constructor)) -#else -# define CONSTRUCTOR -# if defined (__sun) -# pragma init(fat_init) -# endif -#endif - /* Disable use of ifunc for now. Problem is, there's no guarantee that one can call any libc functions from the ifunc resolver. On x86 and x86_64, the corresponding IRELATIVE relocs are supposed to be diff --git a/nettle-types.h b/nettle-types.h index b4f1c1a0..08621079 100644 --- a/nettle-types.h +++ b/nettle-types.h @@ -39,21 +39,16 @@
/* Attributes we want to use in installed header files, and hence can't rely on config.h. */ -#ifdef __GNUC__ - -#define _NETTLE_ATTRIBUTE_PURE __attribute__((pure)) -#ifndef _NETTLE_ATTRIBUTE_DEPRECATED -/* Variant without message is supported since gcc-3.1 or so. */ -#define _NETTLE_ATTRIBUTE_DEPRECATED __attribute__((deprecated)) +#ifdef __has_attribute +# if __has_attribute (__pure__) +# define _NETTLE_ATTRIBUTE_PURE __attribute__((__pure__)) +# else +# define _NETTLE_ATTRIBUTE_PURE +# endif +#else +# define _NETTLE_ATTRIBUTE_PURE #endif
-#else /* !__GNUC__ */ - -#define _NETTLE_ATTRIBUTE_PURE -#define _NETTLE_ATTRIBUTE_DEPRECATED - -#endif /* !__GNUC__ */ - #ifdef __cplusplus extern "C" { #endif 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] = {