Skip to content

Commit

Permalink
Make rng code play nicely with DebugHeap and VerifyHeap.
Browse files Browse the repository at this point in the history
Use is:list(v) rather than Type(v) == T_List to avoid a DebugHeap crash
when v isn't a list.
Reserve space for array header and array block to avoid a verifier crash
if a collection happens between the two allocations.
  • Loading branch information
Don-Ward committed Jan 9, 2024
1 parent d876cc4 commit 211c39e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/runtime/fmisc.r
Original file line number Diff line number Diff line change
Expand Up @@ -2713,13 +2713,14 @@ function{0,1} rngbits(n)
if (n == 0 ) n = curtstate->rng->info.property.blockBits;
elems = (((n+7)/8 + sizeof(word) - 1)/sizeof(word));
Protect(ap = (struct b_intarray *) alcintarray(elems), runerr(0));
reserve(Blocks, sizeof(struct b_list) + sizeof(struct b_intarray) + (elems - 1)* sizeof(word));
Protect(ap = (struct b_intarray *) alcintarray(elems), runerr(307));
if (0 > curtstate->rng->info.api.getRandomBits(n, &(ap->a[0]))) {
fail;
}
result.dword = D_List;
result.vword.bptr = (union block *)alclisthdr(elems, (union block *) ap);
Protect(result.vword.bptr = (union block *)alclisthdr(elems, (union block *) ap),runerr(307));
return result;
}
}
Expand Down Expand Up @@ -2767,7 +2768,7 @@ function{0,1} rngbitstring(n)
if ( 0 < curtstate->rng->info.api.getRandomBits(n, bitbuff)) {
/* Allocate a string of the required size for the answer */
Protect(StrLoc(result) = alcstr(NULL, n), runerr(0));
Protect(StrLoc(result) = alcstr(NULL, n), runerr(306));
/* Populate result with '0' and '1' characters.
* The bits are in the natural left to right reading order,
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/oasgn.r
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ int rngAsgnState(struct threadstate *ts, struct descrip v)
* if v is an intArray and the first element is the RNG id and the size
* is right, assign the rest of the array to the Rng State, otherwise refuse.
*/
if ((Type(v) == T_List) &&
if ((is:list(v)) &&
(v.vword.bptr->List.size == elems) &&
(v.vword.bptr->List.listhead->Intarray.title == T_Intarray) &&
(v.vword.bptr->List.listhead->Intarray.a[0] == ts->rng->info.id))
Expand Down

0 comments on commit 211c39e

Please sign in to comment.