Skip to content

Commit 9877463

Browse files
authored
Merge pull request #166 from 9382/master
Fix rare edge cases in VMify to do with randomness (#155)
2 parents 141de77 + 617d7bb commit 9877463

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/prometheus/compiler/compiler.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ function Compiler:createBlock()
6666
repeat
6767
id = math.random(0, 2^24)
6868
until not self.usedBlockIds[id];
69+
self.usedBlockIds[id] = true;
6970

7071
local scope = Scope:new(self.containerFuncScope);
7172
local block = {
@@ -660,13 +661,13 @@ function Compiler:emitContainerFuncBody()
660661
end
661662

662663
local mid = l + math.ceil(len / 2);
663-
local bound = math.random(tb[mid - 1].id, tb[mid].id);
664+
local bound = math.random(tb[mid - 1].id + 1, tb[mid].id);
664665
local ifScope = scope or Scope:new(pScope);
665666

666667
local lBlock = buildWhileBody(tb, l, mid - 1, ifScope);
667668
local rBlock = buildWhileBody(tb, mid, r, ifScope);
668669

669-
return buildIfBlock(ifScope, bound, lBlock, rBlock)
670+
return buildIfBlock(ifScope, bound, lBlock, rBlock);
670671
end
671672

672673
local whileBody = buildWhileBody(blocks, 1, #blocks, self.containerFuncScope, self.whileScope);

0 commit comments

Comments
 (0)