So I have a little program
#include <iostream>
using namespace std;
void lol() {
cout << "How did we get here?"<<std::endl;
}
int main()
{
long a, b, z[10];
cin >> a >> b;
z[a] = b;
}
You can run it via online compiler here
The program has no purpose, but it has one bug or feature - I do not know what it is.
So, if you write something like this
main 13 2015
you'll probably get nothing, but if you enter two magic number 13
and 4196608
you'll get an error. Moreover the program executes function void lol()
and prints the line How did we get here?
.
I've run nm ./main
and found my function void lol()
with the address 0000000000400900
which equals 4196608
(base of the system of numeration is 10).
That means that the program "jumps" for some reason to this address and executes the function void lol()
. Moreover, if I change the first number, nothing will happen.
main 10 4196608
, main 11 4196608
, main 12 4196608
, main 14 4196608
, main 15 4196608
-- all the same, no errors, but as soon as I enter number 13
I get this interesting behaviour.
Can anyone explain what's going on here?