From 84f5b196410ff7413e19d9ca3a0af8bed290e495 Mon Sep 17 00:00:00 2001
From: Marko Grujic <markoog@gmail.com>
Date: Sat, 17 Oct 2026 21:50:29 +0200
Subject: [PATCH] intarray: Parse query_int integers as decimals

Previously the base was 0, so when zero-padded integers were supplied
the parser interpreted the value as octal, and produced a wrong value.

Instead, set the base as decimal, and add regression test too.
---
 contrib/intarray/_int_bool.c       |  2 +-
 contrib/intarray/expected/_int.out | 13 +++++++++++++
 contrib/intarray/sql/_int.sql      |  4 ++++
 3 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/contrib/intarray/_int_bool.c b/contrib/intarray/_int_bool.c
index 4382f882939..5534995ce9f 100644
--- a/contrib/intarray/_int_bool.c
+++ b/contrib/intarray/_int_bool.c
@@ -93,7 +93,7 @@ gettoken(WORKSTATE *state, int32 *val)
 
 					nnn[innn] = '\0';
 					errno = 0;
-					lval = strtol(nnn, NULL, 0);
+					lval = strtol(nnn, NULL, 10);
 					*val = (int32) lval;
 					if (errno != 0 || (long) *val != lval)
 						return ERR;
diff --git a/contrib/intarray/expected/_int.out b/contrib/intarray/expected/_int.out
index fb4086a95ca..c5bf6bf04a5 100644
--- a/contrib/intarray/expected/_int.out
+++ b/contrib/intarray/expected/_int.out
@@ -398,6 +398,19 @@ SELECT '1&(2&(4&(5|!6)))'::query_int;
  1 & 2 & 4 & ( 5 | !6 )
 (1 row)
 
+-- Leading zeros do not make an octal number.
+SELECT '010'::query_int;
+ query_int 
+-----------
+ 10
+(1 row)
+
+SELECT '{10}'::int[] @@ '010'::query_int;
+ ?column? 
+----------
+ t
+(1 row)
+
 -- Test for overflow of the int16 "left" field in findoprnd().
 -- This query uses a balanced binary tree to avoid using too much stack.
 DO $$
diff --git a/contrib/intarray/sql/_int.sql b/contrib/intarray/sql/_int.sql
index 0d30914725e..4e55a01dee2 100644
--- a/contrib/intarray/sql/_int.sql
+++ b/contrib/intarray/sql/_int.sql
@@ -75,6 +75,10 @@ SELECT '1&2&4&5&6'::query_int;
 SELECT '1&(2&(4&(5|6)))'::query_int;
 SELECT '1&(2&(4&(5|!6)))'::query_int;
 
+-- Leading zeros do not make an octal number.
+SELECT '010'::query_int;
+SELECT '{10}'::int[] @@ '010'::query_int;
+
 -- Test for overflow of the int16 "left" field in findoprnd().
 -- This query uses a balanced binary tree to avoid using too much stack.
 DO $$
-- 
2.54.0 (Apple Git-157)

