0

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.

xtweyz
  • 13
  • 4
  • `what is the reason behind of the this length extension?` Are you interested in gcc exact source code and want to go line by line in gcc source code to see why this happened? Do you care about it? The code is invalid - it's not relevant what happens. `They use same compiler GCC ?` You stated that `MinGW GCC 6.3` and `TDM-GCC 4.9.x`. These are different compilers. You did not specify flags used by the compilers, the operating system, library versions, in both cases. Also, the "decompilation tool" might give different result. And the first one looks like compiled by C++. – KamilCuk Oct 09 '22 at 11:28
  • To make it clear. Yes I little bit care not line by line but if have a logical explanation I want to hear that, My code is running in my environment and its manipulating. When I send source code it does not work if they do not use same compiler as mine. TDM has -I -L (which is mingw64/lib) -O arguments, Mingw GCC has no arguments just source code input. Both Windows, And finally my mistake first one compiled by C++, how did you understood? – xtweyz Oct 09 '22 at 11:52
  • You might be interested in https://stackoverflow.com/questions/2397984/undefined-unspecified-and-implementation-defined-behavior . `by C++, how did you` https://en.wikipedia.org/wiki/Name_mangling#C++ – KamilCuk Oct 09 '22 at 12:12

0 Answers0