[vlc-commits] [Git][videolan/vlc][master] lib: avoid negating VLC_EGENERIC error code

Steve Lhomme (@robUx4) gitlab at videolan.org
Sat Jun 29 10:20:03 UTC 2024



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
e9dd4626 by Alaric Senat at 2024-06-29T10:06:00+00:00
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

- - - - -


1 changed file:

- lib/core.c


Changes:

=====================================
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;
     }
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/e9dd462661ef14ac5d3c237e97a4bd5f6a8653fc

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/e9dd462661ef14ac5d3c237e97a4bd5f6a8653fc
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list