[PATCH gnupg] Fix gcc -Wunterminated-string-initialization warnings.

Werner Koch wk at gnupg.org
Wed Apr 30 10:27:15 CEST 2025


Hi!

On Tue, 29 Apr 2025 21:01, Collin Funk said:
> (has_only_base64): Use memchr since calling strchr on a non-NUL
> terminated string is undefined behavior.

Very good catch.  I was my fault 22 years ago:

> -static char bintoasc[64] =
> +static char bintoasc[64] ATTR_NONSTRING =
>         "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
>         "abcdefghijklmnopqrstuvwxyz"
>         "0123456789+/";

That is actually similar code as in g10/armor.c; which however uses
bintoasc[] and thus let the compiler determine the array size.  I can
only speculate that I used the 64 byte array because the inverse
asctobin array has a fixed size on purpose.

Thanks for the patch.  I am going to apply this to all branches.

Regarding the nonstring attribute we need to wait that we can make
libgpg-error 1.55 a requirement.  That version provides the
GPGRT_ATTR_NONSTRING.  For master we might soon make this a dependency
but not for the other branches.


Shalom-Salam,

   Werner


-- 
The pioneers of a warless world are the youth that
refuse military service.             - A. Einstein
-------------- next part --------------
A non-text attachment was scrubbed...
Name: openpgp-digital-signature.asc
Type: application/pgp-signature
Size: 247 bytes
Desc: not available
URL: <https://lists.gnupg.org/pipermail/gnupg-devel/attachments/20250430/c4c8f527/attachment.sig>


More information about the Gnupg-devel mailing list