mirror of
https://github.com/9fans/plan9port.git
synced 2025-01-12 11:10:07 +00:00
sam: avoid out-of-bounds read in rterm
Usually r->nused < r->nalloc and the read is in bounds. But it could in theory be right on the line and reading past the end of the allocation. Make it safe but preserve as much of the old semantics as possible. This use of rterm appears to be only for optimization purposes so the result does not matter for correctness.
This commit is contained in:
parent
6a80119eb5
commit
3ccd61629b
1 changed files with 2 additions and 2 deletions
|
@ -283,8 +283,8 @@ rterm(List *r, Posn p1)
|
|||
|
||||
for(p = 0,i = 0; i<r->nused && p+L(i)<=p1; p+=L(i++))
|
||||
;
|
||||
if(i==r->nused && (i==0 || !T(i-1)))
|
||||
return 0;
|
||||
if(i==r->nused)
|
||||
return i > 0 && T(i-1);
|
||||
return T(i);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue