This is a discussion on RE: OpenSSL breaks with gcc 4.2 - Openssl ; > But it gets cast back to the correct type before it is called. These > casts are done the way they are to get type-safety. Removing that option > strikes me as a bad thing. It does not. Look ...
> But it gets cast back to the correct type before it is called. These
> casts are done the way they are to get type-safety. Removing that option
> strikes me as a bad thing.
It does not. Look closely at how these functions work:
char *PEM_ASN1_read_bio(char *(*d2i)(), const char *name, BIO *bp, char **x,
pem_password_cb *cb, void *u)
unsigned char *p=NULL,*data=NULL;
if (!PEM_bytes_read_bio(&data, &len, NULL, name, bp, cb, u))
p = data;
if (ret == NULL)
Please tell me how the compiler knows what type 'x' should be passed as. If
you pass a pointer to a function as 'd2i' whose first type is not defined as
a 'char **', you get undefined behavior -- how can the compiler possibly use
the correct type's passing rules when it thinks the function takes a 'char
**' and it actuall takes an 'X509 **'.
OpenSSL does *not* cast the function back to the correct (exact) type
before it calls it. Neither does it cast the function's parameters to the
right type. As a result, the code only works by luck. In the case of
'PEM_read_X509', it works if 'char **' and 'X509 **' happen to have the same
function parameter rules. Nothing requires this to be the case.
There is now way the compiler can know how to properly pass 'x' to 'd2i'. A
function cannot call another function whose parameter types it does not know
and can vary.
OpenSSL Project http://www.openssl.org
Development Mailing List email@example.com
Automated List Manager firstname.lastname@example.org