Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in ch9/SparseTable.cpp #61

Open
seffendy opened this issue Jul 9, 2020 · 1 comment
Open

Bug in ch9/SparseTable.cpp #61

seffendy opened this issue Jul 9, 2020 · 1 comment

Comments

@seffendy
Copy link
Collaborator

seffendy commented Jul 9, 2020

In ch9/SparseTable.cpp

P2.assign(L2_n, 0);
L2.assign(1<<L2_n, 0);
for (int i = 0; i <= L2_n; ++i) {
  P2[i] = (1<<i);
  L2[(1<<i)] = i;
}

P1 is a vector and is assigned with L2_n elements of 0 (from index 0 to L2_n-1), but in the iteration, it accesses P2[i = L2_n] which does not exist.

@seffendy
Copy link
Collaborator Author

seffendy commented Jul 9, 2020

Another bug on line-32:

for (int i = 1; P2[i] <= n; ++i)

P2[] is declared as a vector of size L2_n where L2_n is log2(n)+1 (line-16), so line-32 obviously suffers from index out-of-bound.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant