C++ 12.2.0 throws the error
error: cannot convert ‘unsigned char (*)[91]’ to ‘unsigned char**’
on the following c++11 code snippet:
unsigned char buffer[91];
// int i2d_PUBKEY(EVP_PKEY *a, unsigned char **pp);
ptrdiff_t length = i2d_PUBKEY(m_pkey, &buffer);
- Defining
unsigned char *buffer
fixes the error, but leaves the array length unspecified. - I had assumed
unsigned char buffer[91]
decays intounsigned char *buffer
.
Explicitely casting like i2d_PUBKEY(m_pkey, (unsigned char **)&buffer)
makes the error go away, but the code segfaults then. I suppose there is something fundamental I don't understand with respect to C++ arrays.
Can someone tell me how to write the code above so it works as intended?