Branch: refs/heads/master Author: xiota github@mentalfossa.com Committer: xiota github@mentalfossa.com Date: Sat, 04 Mar 2023 20:21:32 UTC Commit: a9914c7df9729cf8db4c5e9f5f20082c68fd158c https://github.com/geany/geany-plugins/commit/a9914c7df9729cf8db4c5e9f5f2008...
Log Message: ----------- Markdown: Modify replace_all to avoid infinite loop
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).
plugins-commits@lists.geany.org