use nonnull attribute when available

Set this attribute on a few string to avoid compiler warnings from
-Wunterminated-string-initialization warnings in recent gcc.
This commit is contained in:
Damien Miller committed 2026-03-29 16:42:33 +11:00
1 parent bdaf65ae51
commit c90f46b623
4 files changed
+20 -3

No files matched your search

+2 -2
View File
@@ -48,8 +48,8 @@ typedef struct chacha_ctx chacha_ctx;
a = PLUS(a,b); d = ROTATE(XOR(d,a), 8); \
c = PLUS(c,d); b = ROTATE(XOR(b,c), 7);
static const char sigma[16] = "expand 32-byte k";
static const char tau[16] = "expand 16-byte k";
static const char __attribute__ ((__nonstring__)) sigma[16] = "expand 32-byte k";
static const char __attribute__ ((__nonstring__)) tau[16] = "expand 16-byte k";
void
chacha_keysetup(chacha_ctx *x,const u8 *k,u32 kbits)
+13
View File
@@ -358,6 +358,19 @@ AC_COMPILE_IFELSE(
[ AC_MSG_RESULT([no]) ]
)
saved_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -Werror"
AC_MSG_CHECKING([if compiler supports __nonstring__ attribute on char arrays])
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[#include <stdlib.h>]],
[[ char __attribute__ ((__nonstring__)) h[5] = "hello"; return h[0]!='h'; ]])],
[ AC_MSG_RESULT([yes])
AC_DEFINE(HAVE_ATTRIBUTE__NONSTRING__, [1],
[compiler supports nonstring attribute]) ],
[ AC_MSG_RESULT([no]) ]
)
CFLAGS="$saved_CFLAGS"
if test "x$no_attrib_nonnull" != "x1" ; then
AC_DEFINE([HAVE_ATTRIBUTE__NONNULL__], [1], [Have attribute nonnull])
fi
+4
View File
@@ -604,6 +604,10 @@ struct winsize {
# define __nonnull__(x)
#endif
#if !defined(HAVE_ATTRIBUTE__NONSTRING__) && !defined(__nonstring__)
# define __nonstring__
#endif
#ifndef OSSH_ALIGNBYTES
#define OSSH_ALIGNBYTES (sizeof(int) - 1)
#endif
+1 -1
View File
@@ -73,7 +73,7 @@ static void
bcrypt_hash(uint8_t *sha2pass, uint8_t *sha2salt, uint8_t *out)
{
blf_ctx state;
uint8_t ciphertext[BCRYPT_HASHSIZE] =
uint8_t __attribute__ ((__nonstring__)) ciphertext[BCRYPT_HASHSIZE] =
"OxychromaticBlowfishSwatDynamite";
uint32_t cdata[BCRYPT_WORDS];
int i;