recently In my Algorithm design course lab coded some brute force function, it works perfectly in lab but after trying to compile again in my Desktop pc it did not run, so I decompiled and saw the results that I going to attach it.
In my Desktop PC I use MinGW GCC 6.3
LAB PC use TDM-GCC 4.9.2 But compiled by g++ Both windows 10 Both No Specific arguments
#define SIZE 5
int bruteForce()
{
/*
char str[ENOUGH];
sprintf(str, "%d", 42);
*/
for(int i = 0; i < 100000; i++)
{
char str[SIZE];
sprintf(str, "%05d", i);
printf("%s ", str);
if(isValid(str) == 1)
{
return 1;
}
}
return 0;
}
I have this function, Compiled in lab computer, Decompiled version;
undefined8 _Z10bruteForcev(void)
{
bool bVar1;
undefined7 extraout_var;
char local_18 [12];
uint local_c;
local_c = 0;
while( true ) {
if (99999 < (int)local_c) {
return 0;
}
sprintf(local_18,"%d",(ulonglong)local_c);
bVar1 = _Z7isValidPc(local_18);
if ((int)CONCAT71(extraout_var,bVar1) == 1) break;
local_c = local_c + 1;
}
return 1;
}
Compiled in Home Desktop computer, Decompiled version;
undefined4 _bruteForce(void)
{
bool bVar1;
undefined3 extraout_var;
char local_16 [5];
int local_10;
local_10 = 0;
while( true ) {
if (99999 < local_10) {
return 0;
}
_sprintf(local_16,"%05d",local_10);
_printf("%s ",local_16);
bVar1 = _isValid(local_16);
if (CONCAT31(extraout_var,bVar1) == 1) break;
local_10 = local_10 + 1;
}
return 1;
}
as you see one of them has 12 length array and the other one has 5 as I expected, So what is the reason behind of the this length extension? They use same compiler GCC ?
Note: I know size of defined array is not enough and it not works after 9999 because of null character \0
. So correct way is SIZE + 1 = 6.
Thanks.