Skip to content

Commit

Permalink
Make the segfault great again.
Browse files Browse the repository at this point in the history
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)) --> :)
  • Loading branch information
Iwan committed Apr 22, 2017
1 parent d3580df commit e834cbe
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion fastreplacestring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit e834cbe

Please sign in to comment.