3 ms·
The problem in the article is something like this: int main() { unsigned char foo = 0x80; unsigned int x = foo << 24; } and with ubsan
by kzrdude 5y ago
The problem in the article is something like this:
int main() {
unsigned char foo = 0x80;
unsigned int x = foo << 24;
}
and with ubsan enabled it says
/app/example.c:5:30: runtime error: left shift of 128 by 24 places cannot be represented in type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /app/example.c:5:30 in
What's non-obvious is also the rules around arithmetic. Types unsigned char and unsigned int are mentioned in my snippet but the arithmetic - the `<<` operator - performed using the type int.