Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vvmkM-0024lV-1c for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Feb 2026 01:34:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vvmkK-00H9if-1x for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Feb 2026 01:34:24 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vvmkK-00H9iH-0c for pgsql-hackers@lists.postgresql.org; Fri, 27 Feb 2026 01:34:24 +0000 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vvmkH-00000001Op0-0bDN for pgsql-hackers@lists.postgresql.org; Fri, 27 Feb 2026 01:34:23 +0000 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-824b05d2786so1303573b3a.2 for ; Thu, 26 Feb 2026 17:34:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772156061; x=1772760861; darn=lists.postgresql.org; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=t1964uLK6ViikPJ5vLnf8WGLjXjgzVsGwZzDdVyvwJM=; b=arTNlPFXfFRHbMX9VKQAFySnzzVRV7YjVlJTkvsZAPZLatbhTT2E79n6WmJDvWQrPI YxLMZDtQJ2s9W6oQfuspR9BUUE3rUeBR7EMR5DFuzMYDVX6uiEXcjbt0Z+fRUR+WSOqC r5P2jQEAZYU0tVwxEbDJZhLrGnNNv6FtHuuoJX9UE8WqE/VrDUVJl+W+TeQVEiNX3BH9 qBDx4xGYyFyROaufLfytVslEcmvjdRyt8SHi/ewcZuuWiZhIDYHTIpXeNRSkkAhj69GH LMi66RTugEFcf9W/rZh3bqdZGWAjruUHEvtkT66T7JXBdvisLFr2AxxFZ7DZwAmKoASH fHZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772156061; x=1772760861; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=t1964uLK6ViikPJ5vLnf8WGLjXjgzVsGwZzDdVyvwJM=; b=i9zyCQM+AMuRIQU938B5a1QKKRtqj6Bjo6m6aD8uNxKpDcHiLqw4/j9iTSbonpf7rK GupRosH8FzphPgR/0fCBUNWdWwnZ5aqUxTz6nNRzFLsnxEcbMKas4TJZSd60dMpJlT9x QU/EKfWNvCTqynhsh0mHkhKwv9P3a86hMNNYBom/P5Nv9G/9ybUWVO9G7rTsvWoTIpH1 mjGzKmgFPmG77JOOdKxp/A+bAseSNeIcO5SDzEL7UW1xuhJnFPC2qO6AaIoyHQ5YUllW leeGlS9d1tMK9YjGRQ/GzFiKn3AG3TK11Zet5kUsfCKUU6BCgCmE26vg5Q0SwKhM4Wus +Ayg== X-Forwarded-Encrypted: i=1; AJvYcCWo+WETN3D+MQ4W/iMpxN6yBx7tEU/WDqjaH9xxOK/P4mzlD3GPWWOAIPp8cMI4FaXwPQV02wb1q2W2Vlm+@lists.postgresql.org X-Gm-Message-State: AOJu0YzUkpo3ch4YDG3wkfdgB0ib+OhPoNkeeXJZuHxKrpzNrkl5wj3l MTh5eCoGBTRgX4OAH+M5UHWi+ZBrUZf5PMO/svqDd36RWoaQr4eiQaUU X-Gm-Gg: ATEYQzyOv3zt9rQtdhTpHwsRWgFqhKgQj9kz+c5uOxtGoUjBGT3WBUCU+vlXz/jcTkF qMiy3pfXAepTdLAP0sRwMEmPl/F6JZG50Via3mXCjvf8fWAcWU9ZftgfNtmX6LnwVGSP7PGHB9t QXGcyvX7gn4pRQ9HAHvupHVE/6yU9zCQBymAISdko1jqiC2FhmDR99tmn+xe9Ppezyv+KtoJgZH krnfmzgRXGt8OHFFb58hFS6wTJIFCiGR08s50GWSGEvgg17soKTJEj0Djze7Bjl00e2c0+GEGBL JMZqqj8yjWOUFNsnRznjDbB+YqoKkbYhBaLkN78EkL2bJTNE8vuGw9w87QFnVZ08gTv0tJ6Ygkp slrH466JA0vQHXuwNC16JQ2GllXC0TOGK2hjcF+K0uRlaZuSpuhofe59oer+aEckfrpn7L/Llge du32OjNAMtZRYKloz2hJLgiuRevvBvhJDFENtuw+lD X-Received: by 2002:a05:6a00:3d83:b0:827:2949:805f with SMTP id d2e1a72fcca58-8274da12e76mr793580b3a.51.1772156060643; Thu, 26 Feb 2026 17:34:20 -0800 (PST) Received: from smtpclient.apple ([203.10.98.27]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82739ff34fesm3214293b3a.42.2026.02.26.17.34.18 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Feb 2026 17:34:19 -0800 (PST) From: Chao Li Message-Id: <63229AD5-48DB-417C-9361-EA478DAF57AF@gmail.com> Content-Type: multipart/mixed; boundary="Apple-Mail=_6C9AB3F7-0AC0-4394-8391-199FDD3D7BC0" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.400.21\)) Subject: Re: guc: make dereference style consistent in check_backtrace_functions Date: Fri, 27 Feb 2026 09:33:45 +0800 In-Reply-To: <202602261236.ttanikrvfx6w@alvherre.pgsql> Cc: Junwang Zhao , zhanghu , pgsql-hackers@lists.postgresql.org To: =?utf-8?Q?=C3=81lvaro_Herrera?= References: <202602261236.ttanikrvfx6w@alvherre.pgsql> X-Mailer: Apple Mail (2.3864.400.21) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_6C9AB3F7-0AC0-4394-8391-199FDD3D7BC0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Feb 26, 2026, at 20:37, =C3=81lvaro Herrera = wrote: >=20 > There is at least one more place in the code where this is done. >=20 I did a search with the command: grep -RInE = '\*[[:space:]]*[A-Za-z_][A-Za-z0-9_]*\[0\]' src contrib --include=3D'*.c' Excluding irrelevant results, there are 3 more occurrences: 1 - contrib/basic_archive/basic_archive.c line 105 ``` if (*newval =3D=3D NULL || *newval[0] =3D=3D '\0') return true; ``` Here, the code checks *newval first, which implies that the subsequent = *newval[0] is unintentional syntax. 2 - src/interfaces/ecpg/pgtypeslib/interval.c line 62 ``` int DecodeInterval(char **field, int *ftype, int nf, /* int range, */ int *dtype, struct /* pg_ */ tm *tm, fsec_t = *fsec) { ... if (IntervalStyle =3D=3D INTSTYLE_SQL_STANDARD && *field[0] =3D=3D= '-') { /* Check for additional explicit signs */ bool more_signs =3D false; for (i =3D 1; i < nf; i++) { if (*field[i] =3D=3D '-' || *field[i] =3D=3D = '+') { more_signs =3D true; break; } } ``` 3 - src/backend/utils/adt/datatime.c line 3522 ``` int DecodeInterval(char **field, int *ftype, int nf, int range, int *dtype, struct pg_itm_in *itm_in) { ... if (IntervalStyle =3D=3D INTSTYLE_SQL_STANDARD && nf > 0 && = *field[0] =3D=3D '-') { force_negative =3D true; /* Check for additional explicit signs */ for (i =3D 1; i < nf; i++) { if (*field[i] =3D=3D '-' || *field[i] =3D=3D = '+') { force_negative =3D false; break; } } } ``` Where 2&3 makes this patch more interesting. Both occurrences are inside functions named DecodeInterval. For non-zero = i, the code also performs *field[i]: Given this code has been there for years, I don=E2=80=99t believe it is = a bug. I checked the callers of DecodeInterval in both files and found = that field is defined as: ``` char *field[MAXDATEFIELDS]; ``` This explains why *field[i] works; it is doing the intended thing by = getting the first character of the string at array position i. However, since the precedence between the [] and * operators frequently = confuses people, I suggest adding parentheses to make the intention = explicit as *(field[i]). Furthermore, I think we should change the = function signatures to use the type char *field[] to reflect the actual = type the functions expect. If a caller were to pass a true char ** typed = field to DecodeInterval, the current logic would result in a bug. See the attached diff for my suggested changes. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/ --Apple-Mail=_6C9AB3F7-0AC0-4394-8391-199FDD3D7BC0 Content-Disposition: attachment; filename=nocfbot.diff Content-Type: application/octet-stream; x-unix-mode=0644; name="nocfbot.diff" Content-Transfer-Encoding: 7bit diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c index 90946db72ff..7d845700163 100644 --- a/src/backend/utils/adt/datetime.c +++ b/src/backend/utils/adt/datetime.c @@ -3483,7 +3483,7 @@ ClearPgItmIn(struct pg_itm_in *itm_in) * suffices. */ int -DecodeInterval(char **field, int *ftype, int nf, int range, +DecodeInterval(char *field[], int *ftype, int nf, int range, int *dtype, struct pg_itm_in *itm_in) { bool force_negative = false; @@ -3519,13 +3519,13 @@ DecodeInterval(char **field, int *ftype, int nf, int range, * to dump in postgres style, not SQL style.) *---------- */ - if (IntervalStyle == INTSTYLE_SQL_STANDARD && nf > 0 && *field[0] == '-') + if (IntervalStyle == INTSTYLE_SQL_STANDARD && nf > 0 && *(field[0]) == '-') { force_negative = true; /* Check for additional explicit signs */ for (i = 1; i < nf; i++) { - if (*field[i] == '-' || *field[i] == '+') + if (*(field[i]) == '-' || *(field[i]) == '+') { force_negative = false; break; @@ -3557,7 +3557,7 @@ DecodeInterval(char **field, int *ftype, int nf, int range, * least one digit; there could be ':', '.', '-' embedded in * it as well. */ - Assert(*field[i] == '-' || *field[i] == '+'); + Assert(*(field[i]) == '-' || *(field[i]) == '+'); /* * Check for signed hh:mm or hh:mm:ss. If so, process exactly @@ -3567,7 +3567,7 @@ DecodeInterval(char **field, int *ftype, int nf, int range, DecodeTimeForInterval(field[i] + 1, fmask, range, &tmask, itm_in) == 0) { - if (*field[i] == '-') + if (*(field[i]) == '-') { /* flip the sign on time field */ if (itm_in->tm_usec == PG_INT64_MIN) @@ -3650,7 +3650,7 @@ DecodeInterval(char **field, int *ftype, int nf, int range, if (*cp != '\0') return DTERR_BAD_FORMAT; type = DTK_MONTH; - if (*field[i] == '-') + if (*(field[i]) == '-') val2 = -val2; if (pg_mul_s64_overflow(val, MONTHS_PER_YEAR, &val)) return DTERR_FIELD_OVERFLOW; @@ -3663,7 +3663,7 @@ DecodeInterval(char **field, int *ftype, int nf, int range, dterr = ParseFraction(cp, &fval); if (dterr) return dterr; - if (*field[i] == '-') + if (*(field[i]) == '-') fval = -fval; } else if (*cp == '\0') diff --git a/src/include/utils/datetime.h b/src/include/utils/datetime.h index f77c6acd8b6..66dd871fd7f 100644 --- a/src/include/utils/datetime.h +++ b/src/include/utils/datetime.h @@ -316,7 +316,7 @@ extern int DecodeTimezone(const char *str, int *tzp); extern int DecodeTimeOnly(char **field, int *ftype, int nf, int *dtype, struct pg_tm *tm, fsec_t *fsec, int *tzp, DateTimeErrorExtra *extra); -extern int DecodeInterval(char **field, int *ftype, int nf, int range, +extern int DecodeInterval(char *field[], int *ftype, int nf, int range, int *dtype, struct pg_itm_in *itm_in); extern int DecodeISO8601Interval(char *str, int *dtype, struct pg_itm_in *itm_in); diff --git a/src/interfaces/ecpg/pgtypeslib/dt.h b/src/interfaces/ecpg/pgtypeslib/dt.h index 00a45799d55..47df0df4739 100644 --- a/src/interfaces/ecpg/pgtypeslib/dt.h +++ b/src/interfaces/ecpg/pgtypeslib/dt.h @@ -311,7 +311,7 @@ do { \ #define TIMESTAMP_IS_NOEND(j) ((j) == DT_NOEND) #define TIMESTAMP_NOT_FINITE(j) (TIMESTAMP_IS_NOBEGIN(j) || TIMESTAMP_IS_NOEND(j)) -int DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct tm *tm, fsec_t *fsec); +int DecodeInterval(char *field[], int *ftype, int nf, int *dtype, struct tm *tm, fsec_t *fsec); int DecodeTime(char *str, int *tmask, struct tm *tm, fsec_t *fsec); void EncodeDateTime(struct tm *tm, fsec_t fsec, bool print_tz, int tz, const char *tzn, int style, char *str, bool EuroDates); void EncodeInterval(struct tm *tm, fsec_t fsec, int style, char *str); diff --git a/src/interfaces/ecpg/pgtypeslib/interval.c b/src/interfaces/ecpg/pgtypeslib/interval.c index e452a088f9e..4d0e75d4dd4 100644 --- a/src/interfaces/ecpg/pgtypeslib/interval.c +++ b/src/interfaces/ecpg/pgtypeslib/interval.c @@ -323,7 +323,7 @@ DecodeISO8601Interval(char *str, * int IntervalStyle = INTSTYLE_POSTGRES; */ int -DecodeInterval(char **field, int *ftype, int nf, /* int range, */ +DecodeInterval(char *field[], int *ftype, int nf, /* int range, */ int *dtype, struct /* pg_ */ tm *tm, fsec_t *fsec) { int IntervalStyle = INTSTYLE_POSTGRES_VERBOSE; @@ -362,7 +362,7 @@ DecodeInterval(char **field, int *ftype, int nf, /* int range, */ * least one digit; there could be ':', '.', '-' embedded in * it as well. */ - Assert(*field[i] == '-' || *field[i] == '+'); + Assert(*(field[i]) == '-' || *(field[i]) == '+'); /* * Try for hh:mm or hh:mm:ss. If not, fall through to @@ -373,7 +373,7 @@ DecodeInterval(char **field, int *ftype, int nf, /* int range, */ DecodeTime(field[i] + 1, /* INTERVAL_FULL_RANGE, */ &tmask, tm, fsec) == 0) { - if (*field[i] == '-') + if (*(field[i]) == '-') { /* flip the sign on all fields */ tm->tm_hour = -tm->tm_hour; @@ -447,7 +447,7 @@ DecodeInterval(char **field, int *ftype, int nf, /* int range, */ if (*cp != '\0') return DTERR_BAD_FORMAT; type = DTK_MONTH; - if (*field[i] == '-') + if (*(field[i]) == '-') val2 = -val2; val = val * MONTHS_PER_YEAR + val2; fval = 0; @@ -459,7 +459,7 @@ DecodeInterval(char **field, int *ftype, int nf, /* int range, */ if (*cp != '\0' || errno != 0) return DTERR_BAD_FORMAT; - if (*field[i] == '-') + if (*(field[i]) == '-') fval = -fval; } else if (*cp == '\0') @@ -622,14 +622,14 @@ DecodeInterval(char **field, int *ftype, int nf, /* int range, */ * to dump in postgres style, not SQL style.) *---------- */ - if (IntervalStyle == INTSTYLE_SQL_STANDARD && *field[0] == '-') + if (IntervalStyle == INTSTYLE_SQL_STANDARD && *(field[0]) == '-') { /* Check for additional explicit signs */ bool more_signs = false; for (i = 1; i < nf; i++) { - if (*field[i] == '-' || *field[i] == '+') + if (*(field[i]) == '-' || *(field[i]) == '+') { more_signs = true; break; --Apple-Mail=_6C9AB3F7-0AC0-4394-8391-199FDD3D7BC0--