Search code examples
c++warningsgcc-warning

warning: value computed is not used


Why do I get this warning message "warning: value computed is not used" at line "BIO_flush(b64);" and how can I get rid of it?

unsigned char *my_base64(unsigned char *input, int length)
{
    BIO *bmem, *b64;
    BUF_MEM *bptr;

    b64 = BIO_new(BIO_f_base64());
    bmem = BIO_new(BIO_s_mem());
    b64 = BIO_push(b64, bmem);
    BIO_write(b64, input, length);
    BIO_flush(b64);
    BIO_get_mem_ptr(b64, &bptr);

    unsigned char *buff = (unsigned char *)malloc(bptr->length+1);
    memcpy(buff, bptr->data, bptr->length-1);
    buff[bptr->length-1] = 0;

    BIO_free_all(b64);

    return buff;
}

Solution

  • The common way to deal with these errors is to "explicitly cast the return value away":

    (void) BIO_flush(b64);
    

    Alternatively you can choose to turn off this warning alltogether by adding the -Wno-unused-value flag.


    The above obviously assumes you are not interested in the return value. If you are unsure, look in the documentation exactly what it returns and decide whether you want to store/use this or not.