Hacker News new | ask | show | jobs
by jwilk 3249 days ago
Compile this program with -fsanitize=undefined:

  #include <stddef.h>
  #include <inttypes.h>
  
  int main(int argc, char **argv)
  {
  	uint8_t msg[] = { 255 };
  	size_t i = 0;
  	size_t c_index = 255;
  	return msg[i] << ((c_index % 4) * 8);
  }
You get:

  runtime error: left shift of 255 by 24 places cannot be represented in type 'int'