[PATCH] Silence 'may be used uninitialized in this function' warnings

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] Silence 'may be used uninitialized in this function' warnings

Jussi Kivilinna-2
* cipher/arcfour.c (selftest): Initialize 'ctx'.
* cipher/ecc-eddsa.c (_gcry_ecc_eddsa_ensure_compact): Initialize
'enc' and 'enclen'.
(_gcry_ecc_eddsa_sign, _gcry_ecc_eddsa_verify): Initialize 'encpklen'.
* mpi/mpi-pow.c (_gcry_mpi_powm): Initialize 'xsize'.
--

Warnings were seen on gcc-s390x build with optimization level -O3.

Signed-off-by: Jussi Kivilinna <[hidden email]>
---
 cipher/arcfour.c   | 2 +-
 cipher/ecc-eddsa.c | 8 ++++----
 mpi/mpi-pow.c      | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/cipher/arcfour.c b/cipher/arcfour.c
index 9e71857c..909e45b2 100644
--- a/cipher/arcfour.c
+++ b/cipher/arcfour.c
@@ -183,7 +183,7 @@ arcfour_setkey ( void *context, const byte *key, unsigned int keylen,
 static const char*
 selftest(void)
 {
-  ARCFOUR_context ctx;
+  ARCFOUR_context ctx = { { 0, }, };
   byte scratch[16];
 
   /* Test vector from Cryptlib labeled there: "from the
diff --git a/cipher/ecc-eddsa.c b/cipher/ecc-eddsa.c
index 2a1a8907..63c0ef3f 100644
--- a/cipher/ecc-eddsa.c
+++ b/cipher/ecc-eddsa.c
@@ -154,8 +154,8 @@ _gcry_ecc_eddsa_ensure_compact (gcry_mpi_t value, unsigned int nbits)
   const unsigned char *buf;
   unsigned int rawmpilen;
   gcry_mpi_t x, y;
-  unsigned char *enc;
-  unsigned int enclen;
+  unsigned char *enc = NULL;
+  unsigned int enclen = 0;
 
   if (!mpi_is_opaque (value))
     return GPG_ERR_INV_OBJ;
@@ -699,7 +699,7 @@ _gcry_ecc_eddsa_sign (gcry_mpi_t input, mpi_ec_t ec,
   unsigned char *rawmpi = NULL;
   unsigned int rawmpilen;
   unsigned char *encpk = NULL; /* Encoded public key.  */
-  unsigned int encpklen;
+  unsigned int encpklen = 0;
   mpi_point_struct I;          /* Intermediate value.  */
   gcry_mpi_t a, x, y, r;
   int b;
@@ -977,7 +977,7 @@ _gcry_ecc_eddsa_verify (gcry_mpi_t input, mpi_ec_t ec,
   int b;
   unsigned int tmp;
   unsigned char *encpk = NULL; /* Encoded public key.  */
-  unsigned int encpklen;
+  unsigned int encpklen = 0;
   const void *mbuf, *rbuf;
   unsigned char *tbuf = NULL;
   size_t mlen, rlen;
diff --git a/mpi/mpi-pow.c b/mpi/mpi-pow.c
index 62b4a808..defd675e 100644
--- a/mpi/mpi-pow.c
+++ b/mpi/mpi-pow.c
@@ -545,7 +545,7 @@ _gcry_mpi_powm (gcry_mpi_t res,
   {
     mpi_size_t i, j, k;
     mpi_ptr_t xp;
-    mpi_size_t xsize;
+    mpi_size_t xsize = 0;
     int c;
     mpi_limb_t e;
     mpi_limb_t carry_limb;
--
2.27.0


_______________________________________________
Gcrypt-devel mailing list
[hidden email]
http://lists.gnupg.org/mailman/listinfo/gcrypt-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Silence 'may be used uninitialized in this function' warnings

GnuPG - Libgcrypt - Dev mailing list
On Tue, 19 Jan 2021 20:14, Jussi Kivilinna said:

> Warnings were seen on gcc-s390x build with optimization level -O3.

In general I don't like to silence such warning because later compiler
versions are often fixed to detect such wrong warnings.  The
initialization may in some cases even inhibit the compiler to detect
other errors.  

> -  ARCFOUR_context ctx;
> +  ARCFOUR_context ctx = { { 0, }, };

The context is initialized in do_arcfour_setkey.  Trailing commas are
not needed and HP compilers may bail out here.

I suggest not to apply this patch.


Salam-Shalom,

   Werner

--
Die Gedanken sind frei.  Ausnahmen regelt ein Bundesgesetz.

_______________________________________________
Gcrypt-devel mailing list
[hidden email]
http://lists.gnupg.org/mailman/listinfo/gcrypt-devel

signature.asc (233 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Silence 'may be used uninitialized in this function' warnings

Jussi Kivilinna-2
On 20.1.2021 14.59, Werner Koch wrote:

> On Tue, 19 Jan 2021 20:14, Jussi Kivilinna said:
>
>> Warnings were seen on gcc-s390x build with optimization level -O3.
>
> In general I don't like to silence such warning because later compiler
> versions are often fixed to detect such wrong warnings.  The
> initialization may in some cases even inhibit the compiler to detect
> other errors.
>
>> -  ARCFOUR_context ctx;
>> +  ARCFOUR_context ctx = { { 0, }, };
>
> The context is initialized in do_arcfour_setkey.  Trailing commas are
> not needed and HP compilers may bail out here.
>
> I suggest not to apply this patch.
>

Ok. I'll leave this one out.

-Jussi

>
> Salam-Shalom,
>
>     Werner
>


_______________________________________________
Gcrypt-devel mailing list
[hidden email]
http://lists.gnupg.org/mailman/listinfo/gcrypt-devel