I am trying to learn about integer overflows in C and C++ from a website. In its tutorial, it uses these lines of code:
info_size = (*n * sizeof(int)); //value of the number multiplied by sizeof(int), assumed to be 4 bytes buffer = malloc(info_size)
where *n is the integer we are trying to store. It gives an example by storing 24 which leads to it allocating 96 bytes. It then goes on to say that if the multiplication exceeds 2147483647 (2^31 – 1), since info_size is an integer, it would recount and it may come out as a negative number.
Even if I were to store something big like 2147483647 shouldn’t it be just 32 bits of 1, therefore only 4 bytes?