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 sanitizer dislikes (1 << 31) #153

Closed
bhaller opened this issue Nov 20, 2021 · 4 comments · Fixed by #154
Closed

undefined behavior sanitizer dislikes (1 << 31) #153

bhaller opened this issue Nov 20, 2021 · 4 comments · Fixed by #154
Labels
bug Something isn't working
Milestone

Comments

@bhaller
Copy link

bhaller commented Nov 20, 2021

UndefinedBehaviorSanitizer complains:

kastore.c:654:46: runtime error: left shift of 1 by 31 places cannot be represented in type 'int'

The relevant line:

if (self->file != NULL && (self->flags & OWN_FILE)) {

The relevant define:

#define OWN_FILE (1 << 31)

The 1 here should be unsigned, I guess, or a shift of less than 31 should be used. I didn't realize that this was undefined behavior in C, but apparently it is?

@jeromekelleher jeromekelleher added the bug Something isn't working label Nov 20, 2021
@jeromekelleher
Copy link
Member

Huh, thanks @bhaller. Ah, the compiler is right here, 1<<31 is INT32_MAX + 1. Doh. So, this is probably a bug on 32 bit platforms.

@jeromekelleher
Copy link
Member

Simple solution is just use 1<<30, no big deal.

@bhaller
Copy link
Author

bhaller commented Nov 20, 2021

Yeah, it shifts into the sign bit. Probably unsigned should be used for all flag values, since one never really wants to be carrying flags around in signed ints...

@jeromekelleher
Copy link
Member

Yeah, that's true.

jeromekelleher added a commit to jeromekelleher/kastore that referenced this issue Nov 21, 2021
jeromekelleher added a commit to jeromekelleher/kastore that referenced this issue Nov 21, 2021
jeromekelleher added a commit to jeromekelleher/kastore that referenced this issue Nov 21, 2021
jeromekelleher added a commit to jeromekelleher/kastore that referenced this issue Nov 21, 2021
jeromekelleher added a commit to jeromekelleher/kastore that referenced this issue Nov 22, 2021
@mergify mergify bot closed this as completed in #154 Nov 22, 2021
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

Successfully merging a pull request may close this issue.

2 participants