Skip to content

Commit

Permalink
Fix a crash on 64-bit systems
Browse files Browse the repository at this point in the history
When index = tail, it will crash on 64-bit systems:

REBCNT out = 0 here:
for (out--; out >= start; out--) {
	//out = 0xFFFFFFFF (or -1 as a signed integer)
	uc = GET_ANY_CHAR(ser, out); //expands to ser->data[out], which
is the same as *(ser->data + out). On 32-bit system, ser->data is
32-bit, so it's equivalent to *(ser->data - 1), which is a valid address,
but wrong content; while on 64-bit system, ser->data is 64-bit, so "out"
has to be promoted to 64-bit integer, which results in *(ser->data +
0xFFFFFFFF), which is not a valid memory location.
    ...
}
  • Loading branch information
zsx committed Sep 10, 2013
1 parent df45336 commit 85d5cc3
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/core/s-trim.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ static REBFLG find_in_uni(REBUNI *up, REBINT len, REBUNI c)
REBCNT out = index;
REBOOL append_line_feed = FALSE;
REBUNI uc;

if (tail == index){
return;
}
// Skip head lines if required:
if (h || !t) {
for (; index < tail; index++) {
Expand Down

2 comments on commit 85d5cc3

@ladislav
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not see the correspondence between the above description and the file contents.

@zsx
Copy link
Owner Author

@zsx zsx commented on 85d5cc3 Sep 24, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm, this commit was made before Carl process those pull request last month. The code referenced in the comment was removed by db1f091.

I will check if this commit is still needed.

Please sign in to comment.