Code in src/port/pgmkdirp.c uses strstr() to find a single character in a string, but strstr() seems to be too generic for this job. Another function, strchr(), might be better suited for this purpose, because it is optimized to search for exactly one character in a string. In addition, if strchr() is used, the compiler doesn't have to generate a terminating \0 byte for the substring, producing slightly smaller code. I'm attaching the patch.

Regards,
Dmitry
From: Dmitry Mityugov <d.mityu...@postgrespro.ru>
Date: Mon, 21 Jul 2025 00:50:35 +0300
Subject: [PATCH] Use strchr() to search for a single character

Code in src/port/pgmkdirp.c uses strstr() to find a single character in a
string, but strstr() seems to be too generic for this job. Another function,
strchr(), might be better suited for this purpose, because it is optimized to
search for exactly one character in a string. In addition, if strchr() is used,
the compiler doesn't have to generate a terminating \0 byte for the substring,
producing slightly smaller code.
---
 src/port/pgmkdirp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/port/pgmkdirp.c b/src/port/pgmkdirp.c
index d943559760d..7d7cea4dd0e 100644
--- a/src/port/pgmkdirp.c
+++ b/src/port/pgmkdirp.c
@@ -73,7 +73,7 @@ pg_mkdir_p(char *path, int omode)
 		if (p[0] == '/' && p[1] == '/')
 		{
 			/* network drive */
-			p = strstr(p + 2, "/");
+			p = strchr(p + 2, '/');
 			if (p == NULL)
 			{
 				errno = EINVAL;
-- 
2.50.1

Reply via email to