Page MenuHome GnuPG

libgcrypt: Add __nonstring__ attribute for data for GCC 15 or later
Open, NormalPublic

Description

In libgcrypt (current), we have a code like:

static const char names[N_COMPONENTS] = "pabgnq";

While it is valid code in C (a bit non-optimized code as it allocates unused NUL, though), newer GCC (15 or later) emits warning:

../../../wg/libgcrypt/cipher/ecc.c: In function 'compute_keygrip':
../../../wg/libgcrypt/cipher/ecc.c:1702:43: warning: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (7 chars into 6 available) [-Wunterminated-string-initialization]
 1702 |   static const char names[N_COMPONENTS] = "pabgnq";
      |                                           ^~~~~~~~

To silence this, let us add __attribute__((__nonstring__)) for these use cases.

Event Timeline

gniibe triaged this task as Normal priority.
gniibe created this task.
gniibe set External Link to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178.Fri, Apr 18, 4:25 AM

IIUC, it's GCC 8 which starts the support of __nonstring__ attribute.