From e834cbed0e71d7e0967ab31f1d67f95af7f05e53 Mon Sep 17 00:00:00 2001 From: Iwan Date: Sat, 22 Apr 2017 20:18:55 +0200 Subject: [PATCH] Make the segfault great again. When copying the final part of the string, after the last found index, I forgot to subtract the length of the word of the replacement. It would copy too much bytes this way. memcpy(temp, pstr, filelen - j) --> segfault memcpy(temp, pstr, filelen - (j + oldLen)) --> :) --- fastreplacestring.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastreplacestring.cpp b/fastreplacestring.cpp index 45f4256..2c33817 100644 --- a/fastreplacestring.cpp +++ b/fastreplacestring.cpp @@ -133,7 +133,7 @@ int main(int argc, char **argv) { temp += newLen; start = j + oldLen; } - memcpy(temp, pstr, filelen - j); + memcpy(temp, pstr, filelen - start); free(s);