From 38c3d87d43397ab600f085e398789f3dea1cd0a5 Mon Sep 17 00:00:00 2001 From: David Rowley Date: Wed, 21 Oct 2026 13:32:24 +1300 Subject: [PATCH] Use Size rather than int for storing strnlen's return ... in fe_memutils.c's pnstrdup(). strnlen() does return size_t, so it seems better to use the Size input parameter to store the return value rather than demote it to int and risk larger values being truncated. Pushing only to master as this doesn't seem like an actual problem. Fixing will hopefully prevent future LLM-triggered reports about this. Author: Chao Li Discussion: https://postgr.es/m/0E717E09-809F-4BC4-B3B1-36BE729DBFAE@gmail.com --- src/common/fe_memutils.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/common/fe_memutils.c b/src/common/fe_memutils.c index e6f8e74929c..6637e056673 100644 --- a/src/common/fe_memutils.c +++ b/src/common/fe_memutils.c @@ -151,7 +151,6 @@ char * pnstrdup(const char *in, Size size) { char *tmp; - int len; if (!in) { @@ -160,16 +159,16 @@ pnstrdup(const char *in, Size size) exit(EXIT_FAILURE); } - len = strnlen(in, size); - tmp = malloc(len + 1); + size = strnlen(in, size); + tmp = malloc(size + 1); if (tmp == NULL) { fprintf(stderr, _("out of memory\n")); exit(EXIT_FAILURE); } - memcpy(tmp, in, len); - tmp[len] = '\0'; + memcpy(tmp, in, size); + tmp[size] = '\0'; return tmp; }