matroska: rejig test to avoid undefined shift behavior
authorVincent Penquerc'h <vincent.penquerch@collabora.co.uk>
Mon, 5 May 2014 13:41:05 +0000 (14:41 +0100)
committerVincent Penquerc'h <vincent.penquerch@collabora.co.uk>
Mon, 5 May 2014 13:44:57 +0000 (14:44 +0100)
Coverity 1195121, 1195120

gst/matroska/ebml-write.c

index 138f470..08868db 100644 (file)
@@ -349,7 +349,7 @@ gst_ebml_write_element_size (guint8 ** data_inout, guint64 size)
 
   if (size != GST_EBML_SIZE_UNKNOWN) {
     /* how many bytes? - use mask-1 because an all-1 bitset is not allowed */
-    while ((size >> ((bytes - 1) * 8)) >= (mask - 1) && bytes <= 8) {
+    while (bytes <= 8 && (size >> ((bytes - 1) * 8)) >= (mask - 1)) {
       mask >>= 1;
       bytes++;
     }
@@ -530,7 +530,7 @@ gst_ebml_write_get_uint_size (guint64 num)
   guint size = 1;
 
   /* get size */
-  while (num >= (G_GINT64_CONSTANT (1) << (size * 8)) && size < 8) {
+  while (size < 8 && num >= (G_GINT64_CONSTANT (1) << (size * 8))) {
     size++;
   }