Prechádzať zdrojové kódy

tests/checkasm/sw_ops: fix signed integer related UB when shifting values

Fixes:
src/tests/checkasm/sw_ops.c:441:34: runtime error: shift exponent 32 is too large for 32-bit type 'int'
src/tests/checkasm/sw_ops.c:591:37: runtime error: shift exponent 32 is too large for 32-bit type 'int'

Signed-off-by: James Almer <jamrial@gmail.com>
James Almer 1 deň pred
rodič
commit
191f7e4869
1 zmenil súbory, kde vykonal 2 pridanie a 2 odobranie
  1. 2 2
      tests/checkasm/sw_ops.c

+ 2 - 2
tests/checkasm/sw_ops.c

@@ -438,7 +438,7 @@ static AVRational rndq(SwsPixelType t)
 {
     const unsigned num = rnd();
     if (ff_sws_pixel_type_is_int(t)) {
-        const unsigned mask = (1 << (ff_sws_pixel_type_size(t) * 8)) - 1;
+        const unsigned mask = UINT_MAX >> (32 - ff_sws_pixel_type_size(t) * 8);
         return (AVRational) { num & mask, 1 };
     } else {
         const unsigned den = rnd();
@@ -588,7 +588,7 @@ static void check_convert(void)
                     .convert.to = o,
                 });
             } else if (isize > osize || !ff_sws_pixel_type_is_int(i)) {
-                uint32_t range = (1 << osize * 8) - 1;
+                uint32_t range = UINT32_MAX >> (32 - osize * 8);
                 CHECK_COMMON_RANGE(name, range, i, o, {
                     .op = SWS_OP_CONVERT,
                     .type = i,