Page MenuHome GnuPG

Dead code in gcry_mpi_scan
Closed, InvalidPublic

Description

When format == GCRYMPI_FMT_SSH, len is set to 0 and then you have code :

if (len && len < 4)
  return gcry_error (GPG_ERR_TOO_SHORT);

and

if (len)
  len -= 4;
if (len && n > len)
  return gcry_error (GPG_ERR_TOO_LARGE);

which is deadcode as len is always 0

Details

Version
1.4.4

Event Timeline

pterjan set Version to 1.4.4.
pterjan added a subscriber: pterjan.

Let the compiler remove it. I added this comment:

/* This test is not strictly necessary and an assert (!len)
   would be sufficient.  We keep this test in case we later
   allow the BUFLEN argument to act as a sanitiy check.  Same
   below. */

That's fine, I am always worried when seeing such dead code that the logic at
this place became wrong

Right, such code should have a comment or use an assert instead. Thanks.