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

Rémi Denis-Courmont remi at remlab.net
Fri Mar 27 17:09:20 CET 2020

Le perjantaina 27. maaliskuuta 2020, 18.00.45 EET Alexandre Janniaux a écrit :
> Hi,
> 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.

You can, but the function will have to cast back to unsigned char * before 
dereference. The pointer can only be dereferenced as uint8_t * or 
unsigned char *.

My point is that there's only two reasonable types for untyped binary data in 
C. The implicit convenient one is void *, and the explicit inconvenient one is 
unsigned char *. Anything else is a bug in the function prototype (and likely 
the implementation).

> > 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.

Do nothing as we have (not) done for 20 years.

Denis and I warned about platform bugs as one of the reasons against using -
Werror. This is but an example.

Реми Дёни-Курмон

More information about the vlc-devel mailing list