Browse Source

lib: avoid negating VLC_EGENERIC error code

`VLC_EGENERIC` is defined to `INT_MIN` and negating as a 32 bits integer
is undefined behavior.
Let's print a custom error message instead, as it will never be a valid
errno value anyway.

Reported by UBSAN:
../../lib/core.c:72:9: runtime error: negation of -2147483648 cannot be represented in type 'int'; cast to an unsigned type to negate this value to itself
pull/163/head
Alaric Senat 2 years ago
committed by Steve Lhomme
parent
commit
e9dd462661
  1. 6
      lib/core.c

6
lib/core.c

@ -65,11 +65,13 @@ libvlc_instance_t * libvlc_new( int argc, const char *const *argv )
if (unlikely (p_libvlc_int == NULL))
goto error;
int ret = libvlc_InternalInit( p_libvlc_int, argc + 1, my_argv );
const int ret = libvlc_InternalInit( p_libvlc_int, argc + 1, my_argv );
if (ret != VLC_SUCCESS)
{
libvlc_InternalDestroy( p_libvlc_int );
libvlc_printerr("%s", vlc_strerror_c(-ret));
const char *error = (ret == VLC_EGENERIC) ? _( "Generic VLC error" )
: vlc_strerror_c( -ret );
libvlc_printerr( "%s", error );
goto error;
}

Loading…
Cancel
Save