From dce109fcd0da3c1379cd64389d03fdef18b52b54 Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@gmail.com>
Date: Thu, 28 Nov 2024 16:38:03 +1300
Subject: [PATCH] Fix MinGW %d vs %lu warnings in back branches.

Commit 352f6f2d used %d to format DWORD values (unsigned long) with
psprintf().  It has format-string checking under gcc, and gcc doesn't
like it.  It seems that MinGW has started compiling this code in recent
versions, perhaps due to a _WINNT value change, so now we see the
warnings.

Commits 495ed0ef and a9bc04b2 already changed it to %lu in 16+.  In
13-15, build farm animal fairywren began warning a couple of months ago,
and in 15 (the first branch with CI) the CompilerWarnings
mingw_cross_warning step began failing around the same time.

This fixes the warning without any change in behavior, because
sizeof(int) == sizeof(long) on this platform and the values are computed
with DWORD expressions that cannot exceed INT_MAX or LONG_MAX.

Back-patch the formatting change from those commits into 13-15.

Reported-by: Andres Freund <andres@anarazel.de>
Reviewed-by:
Discussion: https://postgr.es/m/t2vjrcb3bloxf5qqvxjst6r7lvrefqyecxgt2koy5ho5b5glr2%40yuupmm6whgob
---
 src/backend/utils/adt/pg_locale.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c
index 8f841c1d192..3646c979498 100644
--- a/src/backend/utils/adt/pg_locale.c
+++ b/src/backend/utils/adt/pg_locale.c
@@ -1760,7 +1760,7 @@ get_collation_actual_version(char collprovider, const char *collcollate)
 							collcollate,
 							GetLastError())));
 		}
-		collversion = psprintf("%d.%d,%d.%d",
+		collversion = psprintf("%lu.%lu,%lu.%lu",
 							   (version.dwNLSVersion >> 8) & 0xFFFF,
 							   version.dwNLSVersion & 0xFF,
 							   (version.dwDefinedVersion >> 8) & 0xFFFF,
-- 
2.47.0

