blockbench icon indicating copy to clipboard operation
blockbench copied to clipboard

Fix index overflow bug

Open JimmyShi22 opened this issue 3 years ago • 2 comments

Example: sort(4, xxxx) will be failed. Because in line 28, j is 0, j-- will get a big uint. This will leads to a failure.

JimmyShi22 avatar Feb 21 '22 08:02 JimmyShi22

Hi Jimmy, Thanks for your PR, I think the bus can be fixed by adding a require above line7,

require(size > 0, "Wrong array size");

Actually, j is the number of right index of one array, it should be bigger than 0.

KunPengRen avatar Feb 22 '22 09:02 KunPengRen

So happy can get the reply!

The problem is that, I call the function by sort(4, xxx) or sort(100, xxx), but get revert.

After a long caculation with my pen, i found that in line 28, if j is 0, j-- will get a big uint. So that reqire(size > 0) may not fix this problem.

JimmyShi22 avatar Feb 23 '22 03:02 JimmyShi22