Uninteded Variable Length Array in ec-nist.c

NIIBE Yutaka gniibe at fsij.org
Tue Sep 27 02:54:10 CEST 2022


Hello,

While we allow use of some features of C99 for libgcrypt, we don't use
variable length array in the code.

Thus, I'm considering adding -Wvla option in configure.ac.  In master,
I found use of variable length array in ec-nist.c.  I attach the
warning message of compiler when it is compiled with -Wvla option.

I think that it's not intended.  Unfortunately, even if we added const
qualifier to the variable 'wsize', (because what is needed here is a
constant expression), it is still considered as variable length array by
compilers.

I think that use of macro for the size is needed here, although it would
not look modern code.

==========================
gcc -DHAVE_CONFIG_H -I. -I../../../libgcrypt/mpi -I.. -I../src -I../../../libgcrypt/src -I/usr/local/include/x86_64-linux-gnu -g -O2 -fvisibility=hidden -fno-delete-null-pointer-checks -Wall -Wvla -MT ec-nist.lo -MD -MP -MF .deps/ec-nist.Tpo -c ../../../libgcrypt/mpi/ec-nist.c  -fPIC -DPIC -o .libs/ec-nist.o
../../../libgcrypt/mpi/ec-nist.c: In function '_gcry_mpi_ec_nist192_mod':
../../../libgcrypt/mpi/ec-nist.c:98:3: warning: ISO C90 forbids variable length array 's' [-Wvla]
   98 |   mpi_limb64_t s[wsize + 1];
      |   ^~~~~~~~~~~~
../../../libgcrypt/mpi/ec-nist.c:99:3: warning: ISO C90 forbids variable length array 'o' [-Wvla]
   99 |   mpi_limb64_t o[wsize + 1];
      |   ^~~~~~~~~~~~
../../../libgcrypt/mpi/ec-nist.c: In function '_gcry_mpi_ec_nist224_mod':
../../../libgcrypt/mpi/ec-nist.c:191:3: warning: ISO C90 forbids variable length array 's' [-Wvla]
  191 |   mpi_limb64_t s[wsize];
      |   ^~~~~~~~~~~~
../../../libgcrypt/mpi/ec-nist.c:192:3: warning: ISO C90 forbids variable length array 'd' [-Wvla]
  192 |   mpi_limb64_t d[wsize];
      |   ^~~~~~~~~~~~
../../../libgcrypt/mpi/ec-nist.c: In function '_gcry_mpi_ec_nist256_mod':
../../../libgcrypt/mpi/ec-nist.c:350:3: warning: ISO C90 forbids variable length array 's' [-Wvla]
  350 |   mpi_limb64_t s[wsize + 1];
      |   ^~~~~~~~~~~~
../../../libgcrypt/mpi/ec-nist.c:351:3: warning: ISO C90 forbids variable length array 't' [-Wvla]
  351 |   mpi_limb64_t t[wsize + 1];
      |   ^~~~~~~~~~~~
../../../libgcrypt/mpi/ec-nist.c:352:3: warning: ISO C90 forbids variable length array 'd' [-Wvla]
  352 |   mpi_limb64_t d[wsize + 1];
      |   ^~~~~~~~~~~~
../../../libgcrypt/mpi/ec-nist.c:353:3: warning: ISO C90 forbids variable length array 'e' [-Wvla]
  353 |   mpi_limb64_t e[wsize + 1];
      |   ^~~~~~~~~~~~
../../../libgcrypt/mpi/ec-nist.c: In function '_gcry_mpi_ec_nist384_mod':
../../../libgcrypt/mpi/ec-nist.c:603:3: warning: ISO C90 forbids variable length array 's' [-Wvla]
  603 |   mpi_limb64_t s[wsize + 1];
      |   ^~~~~~~~~~~~
../../../libgcrypt/mpi/ec-nist.c:604:3: warning: ISO C90 forbids variable length array 't' [-Wvla]
  604 |   mpi_limb64_t t[wsize + 1];
      |   ^~~~~~~~~~~~
../../../libgcrypt/mpi/ec-nist.c:605:3: warning: ISO C90 forbids variable length array 'd' [-Wvla]
  605 |   mpi_limb64_t d[wsize + 1];
      |   ^~~~~~~~~~~~
../../../libgcrypt/mpi/ec-nist.c:606:3: warning: ISO C90 forbids variable length array 'x' [-Wvla]
  606 |   mpi_limb64_t x[wsize + 1];
      |   ^~~~~~~~~~~~
../../../libgcrypt/mpi/ec-nist.c: In function '_gcry_mpi_ec_nist521_mod':
../../../libgcrypt/mpi/ec-nist.c:795:3: warning: ISO C90 forbids variable length array 's' [-Wvla]
  795 |   mpi_limb_t s[wsize];
      |   ^~~~~~~~~~
-- 



More information about the Gcrypt-devel mailing list