Unhandled exception in apparently trivial function call

0

I have a function that reads a text file and successfully returns a vector of the small number of lines in the file. I passed this vector to a function to process the lines and it threw an error

Unhandled exception at 0x00267EF9 in Bridge.exe: 0xC00000FD: Stack overflow (parameters: 0x00000000, 0x00A82000). occurred

So, as Ben Voigt pointed out, there was a stack overflow that probably had nothing to do with the function that apparently threw it i.e.

   int LinesToCards(std::vector<std::string>& lines) {
        int retval = -999;
        return retval;
    }

This was called from main which had a line needed by a 3rd party DLL

    int main()
        {
            std::string cards[MAXDEALS][DDS_HANDS][DDS_SUITS] ;
            int retval = -999;        
            retval = LinesToCards(lines);       
            return 0;
    }

The #define DDS_HANDS 4 #define DDS_SUITS 4 cannot be changed but the original working

#define MAXDEALS 999

now throws the exception. If I reduce it to

#define MAXDEALS 890

the code runs again. If I up that to

#define MAXDEALS 891

it crashes. Is there some magic number between 16240 and 16256?

c++
visual-studio
vector
asked on Stack Overflow Dec 6, 2017 by DLyons • edited Dec 7, 2017 by DLyons

1 Answer

1

You're out of stack space.

The function where the failure happens is not the function that's to blame, and that's why it doesn't happen in your small test program.

One of the functions in the call path to the failing code was very greedy and didn't leave enough stack available for the functions it calls.

Look for both large objects on the stack and also too-deep recursion.

answered on Stack Overflow Dec 6, 2017 by Ben Voigt

User contributions licensed under CC BY-SA 3.0