Closed bhaller closed 2 years ago
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.
Simple solution is just use 1<<30, no big deal.
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...
Yeah, that's true.
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?