orcarm: Fix undefined behaviour
authorSebastian Dröge <sebastian@centricular.com>
Fri, 7 Apr 2023 15:57:41 +0000 (18:57 +0300)
committerSebastian Dröge <sebastian@centricular.com>
Fri, 7 Apr 2023 15:57:41 +0000 (18:57 +0300)
Left-shift of a negative signed integer is undefined behaviour. The
value becomes negative because bitwise-not on a positive, signed integer
results in a negative signed integer.

To solve this use unsigned integers. The code assumes that the sign bit
is not treated differently from any other bits.

Part-of: <https://gitlab.freedesktop.org/gstreamer/orc/-/merge_requests/94>

orc/orcarm.c

index 21933d4..2080392 100644 (file)
@@ -1230,7 +1230,7 @@ count_leading_zeros (orc_uint64 val)
  * 64-bit variant: N:immr:imms
  */
 static int
-encode_logical_imm (int size, orc_uint64 val, orc_uint32 *encoded)
+encode_logical_imm (unsigned int size, orc_uint64 val, orc_uint32 *encoded)
 {
   orc_uint64 mask;
   orc_uint32 I, CTO, CLO;