From 4549f5467e1fc62f9d9d386592e1f5859accf930 Mon Sep 17 00:00:00 2001
From: Petter Reinholdtsen <pere@debian.org>
Date: Sat, 8 Mar 2025 11:03:12 +0100
Subject: [PATCH] Avoid undefined shifting of negative number in rate.c.

It is undefined what left-shifting a negative number should do, and the
compiler do not like trying to shift the -64 value 57 bits to the left.

Changed the definition of OC_Q57() to left shift one bit and
use multiplication, to change the operatoin to a well defined one.
Patch from Timothy B_ Terriberry.

This get rid of this clang message:

>  ../../lib/rate.c:746:15: warning: shifting a negative signed value is undefined [-Wshift-negative-value]
>      log_scale=OC_Q57(-64);
>                ^~~~~~~~~~~
>  ../../lib/mathops.h:134:38: note: expanded from macro 'OC_Q57'
>  #define OC_Q57(_v) ((ogg_int64_t)(_v)<<57)
>                      ~~~~~~~~~~~~~~~~~^

MR !23 fixes #2321
---
 lib/mathops.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/mathops.h b/lib/mathops.h
index a1a4f9df..2776dbd6 100644
--- a/lib/mathops.h
+++ b/lib/mathops.h
@@ -131,7 +131,7 @@ int oc_ilog64(ogg_int64_t _v);
  */
 # define OC_STATIC_ILOG_64(_v) (OC_STATIC_ILOG6((ogg_int64_t)(_v)))
 
-#define OC_Q57(_v) ((ogg_int64_t)(_v)<<57)
+#define OC_Q57(_v) ((_v)*((ogg_int64_t)1<<57))
 #define OC_Q10(_v) ((_v)<<10)
 
 ogg_int64_t oc_bexp64(ogg_int64_t _z);
-- 
GitLab