Skip to content

Commit

Permalink
Fixed sdscat*() bug: read memory error
Browse files Browse the repository at this point in the history
  • Loading branch information
iiol committed Jul 6, 2020
1 parent 78df725 commit 91798d8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
Binary file added a.out
Binary file not shown.
17 changes: 17 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <stdio.h>

#include "sds.h"

int
main(void)
{
sds str;

str = sdsnew("asdf");
str = sdscat(str, str);
printf("%s\n", str);

sdsfree(str);

return 0;
}
2 changes: 1 addition & 1 deletion sds.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ sds sdscatlen(sds s, const void *t, size_t len) {

s = sdsMakeRoomFor(s,len);
if (s == NULL) return NULL;
memcpy(s+curlen, t, len);
memmove(s+curlen, t, len);
sdssetlen(s, curlen+len);
s[curlen+len] = '\0';
return s;
Expand Down

0 comments on commit 91798d8

Please sign in to comment.