Branch: refs/heads/master Author: Colomban Wendling ban@herbesfolles.org Committer: GitHub noreply@github.com Date: Thu, 25 Apr 2024 12:24:32 UTC Commit: d851faca7a88e761c624b675549cebbaac21f5bd https://github.com/geany/geany-plugins/commit/d851faca7a88e761c624b675549ceb...
Log Message: ----------- Merge pull request #1232 from xiota/pr-markdown-replace-all
Markdown: Modify replace_all to avoid infinite loop
Fixes #936.
Modified Paths: -------------- markdown/src/viewer.c
Modified: markdown/src/viewer.c 7 lines changed, 5 insertions(+), 2 deletions(-) =================================================================== @@ -194,12 +194,15 @@ replace_all(MarkdownViewer *self, { gchar *ptr; gsize needle_len = strlen(needle); + gsize replacement_len = strlen(replacement); + goffset offset = 0;
/* For each occurrence of needle in haystack */ - while ((ptr = strstr(haystack->str, needle)) != NULL) { - goffset offset = ptr - haystack->str; + while ((ptr = strstr(haystack->str + offset, needle)) != NULL) { + offset = ptr - haystack->str; g_string_erase(haystack, offset, needle_len); g_string_insert(haystack, offset, replacement); + offset += replacement_len; } }
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).