From e9dd462661ef14ac5d3c237e97a4bd5f6a8653fc Mon Sep 17 00:00:00 2001 From: Alaric Senat Date: Fri, 28 Jun 2024 10:08:46 +0200 Subject: [PATCH] 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 --- lib/core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/core.c b/lib/core.c index 6531c2c610..d96cacaca9 100644 --- a/lib/core.c +++ b/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; }