[gnutls-help] gnutls-3.2.13 : another code bug "base64.c", line 99: error: void function cannot return value

dev dev at cor0.com
Wed Apr 30 00:24:29 CEST 2014


I just checked and sure enough the code is trying to
return a value from a static void function :


First we have the static voide func :


/* Base64 encode IN array of size INLEN into OUT array. OUT needs
   to be of length >= BASE64_LENGTH(INLEN), and INLEN needs to be
   a multiple of 3.  */
static void
base64_encode_fast (const char *restrict in, size_t inlen, char
*restrict out)
{
  while (inlen)
    {
      *out++ = b64c[to_uchar (in[0]) >> 2];
      *out++ = b64c[((to_uchar (in[0]) << 4) + (to_uchar (in[1]) >> 4))
& 0x3f];
      *out++ = b64c[((to_uchar (in[1]) << 2) + (to_uchar (in[2]) >> 6))
& 0x3f];
      *out++ = b64c[to_uchar (in[2]) & 0x3f];

      inlen -= 3;
      in += 3;
    }
}



Then down here a little we have this mess :

void
base64_encode (const char *restrict in, size_t inlen,
               char *restrict out, size_t outlen)
{
  /* Note this outlen constraint can be enforced at compile time.
     I.E. that the output buffer is exactly large enough to hold
     the encoded inlen bytes.  The inlen constraints (of corresponding
     to outlen, and being a multiple of 3) can change at runtime
     at the end of input.  However the common case when reading
     large inputs is to have both constraints satisfied, so we depend
     on both in base_encode_fast().  */
  if (outlen % 4 == 0 && inlen == outlen / 4 * 3)
    return base64_encode_fast (in, inlen, out);


That right there is just plain wrong.


How can you return a value from a void function ?

Does this stuff compile with GCC and it seems to work ?

How is that even possible ?


Dennis



More information about the Gnutls-help mailing list