You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudberry.apache.org by "tuhaihe (via GitHub)" <gi...@apache.org> on 2026/07/14 02:24:16 UTC

Re: [PR] Fix infinite loop in replaceStringInfoString [cloudberry]

tuhaihe commented on code in PR #1750:
URL: https://github.com/apache/cloudberry/pull/1750#discussion_r3575612971


##########
src/common/stringinfo.c:
##########
@@ -361,16 +361,32 @@ enlargeStringInfo(StringInfo str, int needed)
 void
 replaceStringInfoString(StringInfo str, char *replace, char *replacement)
 {
-	char	*ptr;
+	char	*match_ptr = NULL;
+	char	*start_ptr = str->data;
+	char	*dup = NULL;
+	size_t	replace_len = strlen(replace);
 
-	while ((ptr = strstr(str->data, replace)) != NULL)
-	{
-		char	   *dup = pstrdup(str->data);
+	// prevent empty loop, cuz strstr will always return start_ptr

Review Comment:
   ```suggestion
   	// prevent empty loop, because strstr will always return start_ptr
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org