Skip to content

Commit

Permalink
Merge pull request #61 from hostilefork/fix-mem-errors
Browse files Browse the repository at this point in the history
two memcpy to memmove changes, fix use of uninitialized err value
  • Loading branch information
carls committed Jan 22, 2013
2 parents 90c2fe8 + 27f6200 commit 374dedf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/core/c-do.c
Original file line number Diff line number Diff line change
Expand Up @@ -1813,7 +1813,8 @@ x*/ static REBINT Do_Args_Light(REBVAL *func, REBVAL *path, REBSER *block, REBCN

// Copy values to prior location:
inew--;
memcpy(DS_ARG(1), DS_TOP-(inew-1), inew * sizeof(REBVAL));
// memory areas may overlap, so use memmove and not memcpy!
memmove(DS_ARG(1), DS_TOP-(inew-1), inew * sizeof(REBVAL));
DSP = DS_ARG_BASE + inew; // new TOS
//Dump_Block(DS_ARG(1), inew);
VAL_WORD_FRAME(DSF_WORD(DSF)) = VAL_FUNC_BODY(func_val);
Expand Down
5 changes: 4 additions & 1 deletion src/core/n-loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,8 @@
if ((err = Check_Error(ds)) >= 0) break;
// else CONTINUE:
if (mode == 1) SET_FALSE(ds); // keep the value (for mode == 1)
} else {
err = 0; // prevent later test against uninitialized value
}

if (mode > 0) {
Expand All @@ -426,7 +428,8 @@
if (mode == 1) { // remove-each
if (IS_FALSE(ds)) {
REBCNT wide = SERIES_WIDE(series);
memcpy(series->data + (windex * wide), series->data + (rindex * wide), (index - rindex) * wide);
// memory areas may overlap, so use memmove and not memcpy!
memmove(series->data + (windex * wide), series->data + (rindex * wide), (index - rindex) * wide);
windex += index - rindex;
// old: while (rindex < index) *BLK_SKIP(series, windex++) = *BLK_SKIP(series, rindex++);
}
Expand Down

0 comments on commit 374dedf

Please sign in to comment.