]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix 64-bit shifting in dynahash.c
authorPeter Eisentraut <peter@eisentraut.org>
Sun, 19 Apr 2026 10:57:41 +0000 (12:57 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Sun, 19 Apr 2026 11:27:54 +0000 (13:27 +0200)
The switch from long to int64 in commit 13b935cd521 was incomplete.
It was shifting the constant 1L, which is not always 64 bit.  Fix by
using an explicit int64 constant.

MSVC warning:

../src/backend/utils/hash/dynahash.c(1767): warning C4334: '<<': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

Also add the corresponding warning to the standard warning set on
MSVC, to help catch similar issues in the future.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/1142ad86-e475-41b3-aeee-c6ad913064fa%40eisentraut.org

meson.build
src/backend/utils/hash/dynahash.c

index 7f82876dbc82650cc4250058354a01a9dd493cc0..60c8cdc3a0602192ad8cf27eaff1c02d1924ad74 100644 (file)
@@ -2331,6 +2331,10 @@ if cc.get_id() == 'msvc'
     '/w24062', # enumerator 'identifier' in switch of enum 'enumeration' is not handled [like -Wswitch]
     '/w24102', # unreferenced label [like -Wunused-label]
 
+    # This one doesn't match a gcc warning, but it can help catch
+    # issues related to 4-byte long on Windows.
+    '/w24334', # 'operator': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)
+
     # Turn this into an error, to match other compilers (as of C99)
     '/we4013', # 'function' undefined; assuming extern returning int' [like -Wimplicit-function-declaration]
   ]
index 20610f96e7b1efd1ebd0386ed35ce9c39beeb6cb..dc7ae64a5a98fb0ea9704aea44210fedb0bbcca7 100644 (file)
@@ -1764,7 +1764,7 @@ static int64
 next_pow2_int64(int64 num)
 {
        /* my_log2's internal range check is sufficient */
-       return 1L << my_log2(num);
+       return INT64CONST(1) << my_log2(num);
 }
 
 /* calculate first power of 2 >= num, bounded to what will fit in an int */