[vlc-commits] keys: fix signed overflow

Rémi Denis-Courmont git at videolan.org
Wed Aug 20 20:20:02 CEST 2014


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Aug 20 21:19:52 2014 +0300| [8011d4e36797a320c788844085d5ce15848a3e0c] | committer: Rémi Denis-Courmont

keys: fix signed overflow

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8011d4e36797a320c788844085d5ce15848a3e0c
---

 modules/video_output/xcb/keysym.c |   15 ++++++++-------
 src/config/keys.c                 |    4 ----
 2 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/modules/video_output/xcb/keysym.c b/modules/video_output/xcb/keysym.c
index f95416d..ad4e31c 100644
--- a/modules/video_output/xcb/keysym.c
+++ b/modules/video_output/xcb/keysym.c
@@ -32,18 +32,19 @@ struct keysym
 {
     char xname[32];
     char uname[64];
-    int32_t xsym;
-    int32_t usym;
+    uint32_t xsym;
+    uint32_t usym;
 };
 
 static int cmpkey (const void *va, const void *vb)
 {
     const struct keysym *ka = va, *kb = vb;
 
-#if (INT_MAX < 0x7fffffff)
-# error Oups!
-#endif
-    return ka->xsym - kb->xsym;
+    if (ka->xsym > kb->xsym)
+        return +1;
+    if (ka->xsym < kb->xsym)
+        return -1;
+    return 0;
 }
 
 static void printkey (const void *node, const VISIT which, const int depth)
@@ -79,7 +80,7 @@ static int parse (FILE *in)
             abort ();
 
         int val = sscanf (line,
-                          "#define XK_%31s %"SCNi32" /*%*cU+%"SCNx32" %63[^*]",
+                          "#define XK_%31s %"SCNu32" /*%*cU+%"SCNx32" %63[^*]",
                           sym->xname, &sym->xsym, &sym->usym, sym->uname);
         if (val < 3)
         {
diff --git a/src/config/keys.c b/src/config/keys.c
index cff9ea9..b247a57 100644
--- a/src/config/keys.c
+++ b/src/config/keys.c
@@ -386,11 +386,7 @@ static int keycmp (const void *a, const void *b)
 {
     const struct mapping *ka = a, *kb = b;
 
-#if (INT_MAX >= 0x7fffffff)
-    return ka->key - kb->key;
-#else
     return (ka->key < kb->key) ? -1 : (ka->key > kb->key) ? +1 : 0;
-#endif
 }
 
 struct vlc_actions



More information about the vlc-commits mailing list