[gnutls-devel] Casting from int to (void *)

Jaak Ristioja jaak.ristioja at cyber.ee
Tue Feb 5 17:23:31 CET 2013


Hello!

According to the documentation GnuTLS functions like
gnutls_transport_set_ptr can also be used for berkeley style sockets
descriptors, but unfortunately converting between int and void * types
is not always good thing to do:


https://www.securecoding.cert.org/confluence/display/seccode/INT11-C.+Converting+a+pointer+to+integer+or+integer+to+pointer

https://www.securecoding.cert.org/confluence/display/cplusplus/INT11-CPP.+Take+care+when+converting+from+pointer+to+integer+or+integer+to+pointer

Compilers like GCC and Clang also complain about casting the (int)
socket descriptors to void * types.

Perhaps it were better to provide a gnutls_transport_set_berkeley
function which would accept berkeley-style (int) socket descriptors
instead. The idea is that if gnutls_transport_set_ptr or
gnutls_transport_set_ptr2 is used the push and pull callbacks must also
be set, but if gnutls_transport_set_berkeley is used, the callbacks are
not used.

Afaik using intptr_t could also be an option, but in that case one has
to verify that all values of type int fit into intptr_t.

Best regards,
Jaak



More information about the Gnutls-devel mailing list