From 843fa4168af4d0fe6278a5373793d37eb811affb Mon Sep 17 00:00:00 2001 From: ckolivas Date: Fri, 13 Feb 2026 12:07:24 +1100 Subject: [PATCH] Address undefined warnings from compilers for left shifting negative integers in zpaq. --- libzpaq/libzpaq.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libzpaq/libzpaq.cpp b/libzpaq/libzpaq.cpp index 633c6f1..42d9f58 100644 --- a/libzpaq/libzpaq.cpp +++ b/libzpaq/libzpaq.cpp @@ -801,7 +801,11 @@ void Predictor::init() { cr.cm.resize(512); for (int j=0; j<256; ++j) { cr.cm[j*2]=1<<15; - cr.cm[j*2+1]=clamp512k(stretch(st.cminit(j)>>8)<<10); + // Left shift of negative values is undefined strictly speaking so + // cast it back and forth to safely perform left shift and avoid + // compiler issues. Original code: + // cr.cm[j*2+1]=clamp512k(stretch(st.cminit(j)>>8)<<10); + cr.cm[j*2+1]=clamp512k(static_cast(static_cast(stretch(st.cminit(j) >> 8)) << 10)); } break; case SSE: // sizebits j start limit