[vlc-devel] [PATCH v2] access_output: udp: fix conversion from uint8_t* on Windows

Alexandre Janniaux ajanni at videolabs.io
Fri Mar 27 17:00:45 CET 2020


On Fri, Mar 27, 2020 at 05:39:18PM +0200, Rémi Denis-Courmont wrote:
> Le perjantaina 27. maaliskuuta 2020, 17.10.49 EET Alexandre Janniaux a écrit :
> > Like discussed on the mailing list, casting to char* would be incorrect
> You have a uint8_t * here. You can only convert it to unsigned char * (1) or
> keep it as is.

No I can cast to (void*) without aliasing issues, as far as I know.

> Casting it to void * to mute pointer type warnings is something that we have
> consistently rejected, as it essentially amounts to hiding bugs.

I agree, it's a much better argument, but the other workarounds I can
think of so far are:

+ wrap read() in a macro on Windows to use the correct type, which is
  awful, can lead to misleading warnings depending on includes and is
  more or less the same.

+ wrap read in a function and apply the correct fix for Windows here
  which is better but could non-intuitive. Adding warnings on usage of
  read/recv/write/send without going to the wrapper could help though.

+ rename the function in Microsoft headers with defines, and wrap the
  symbol to ensure we use the same prototype everywhere, but it could
  stop working if it is declared with parenthesis in Microsoft headers
  and could break even more things.

Given that POSIX function are already taking `void *` and this are not
subject to pointer type warnings, I found it less harmful to have it
casted to `(void*)` too than relying on such mechanism.

Among the 3 suggestions above, only the second is a workable one to me.

Alexandre Janniaux

More information about the vlc-devel mailing list