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

Undefined behavior #7

Closed
zeeev opened this issue Apr 2, 2021 · 7 comments
Closed

Undefined behavior #7

zeeev opened this issue Apr 2, 2021 · 7 comments
Labels
bug Something isn't working

Comments

@zeeev
Copy link

zeeev commented Apr 2, 2021

Dear @lh3,

While running sanitation (address,undefined), I hit errors in IITree. I attempted debugging, but was unable to figure out the shifts. I would really appreciate it if you could take a look at this undefined behavior, and variable name masking. Let me know if I can help in any way.

Best wishes,

Zev

+  SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../src/third-party/cgranges/IITree.h:84:41 in
+  ../src/third-party/cgranges/IITree.h:84:54: runtime error: signed integer overflow: -9223372036854775808 - 1 cannot be represented in type 'long long'
+  SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../src/third-party/cgranges/IITree.h:84:54 in
+  ../src/third-party/cgranges/IITree.h:88:24: runtime error: shift exponent -1 is negative
+  SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../src/third-party/cgranges/IITree.h:88:24 in
+  ../src/third-party/cgranges/IITree.h:88:31: runtime error: shift exponent -1 is negative
+  SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../src/third-party/cgranges/IITree.h:88:31 in
@lh3
Copy link
Owner

lh3 commented Apr 4, 2021

What is the value of max_level? Do you use any negative numbers? PS: probably you are using an empty list.

@zeeev
Copy link
Author

zeeev commented Apr 5, 2021

Dear @lh3,

Thanks for the reply. How can I check the max level? I'm using the cpp api. I assume I'm using the default. If a tree is empty is there a way to check first? I know these are pedantic issues, but I'd like to pass UBSAN and No warnings if possible.

Best,

Zev

@lh3
Copy link
Owner

lh3 commented Apr 5, 2021

You can modify IITree::overlap() such that it directly returns when max_level is negative. If that works, I can make the change on my end. Thanks.

@zeeev
Copy link
Author

zeeev commented Apr 5, 2021

Hi @lh3,

	bool overlap(const S &st, const S &en, std::vector<size_t> &out) const {
		int t = 0;
		StackCell stack[64];
		out.clear();
		if(max_level < 0) return false;

This did the trick. All UBSAN tests passing.

@pb-cdunn
Copy link

pb-cdunn commented Apr 7, 2021

Yes, this is a good fix. It occurs after calling index() on an empty tree.

@lh3 lh3 closed this as completed in 6da7237 Apr 7, 2021
@lh3
Copy link
Owner

lh3 commented Apr 7, 2021

Thanks for the confirmation. Changes made.

@lh3 lh3 added the bug Something isn't working label Apr 7, 2021
@zeeev
Copy link
Author

zeeev commented Apr 7, 2021

Thanks @lh3!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants