-2

I am having following exception during the course of the run of program:

0 [main] myFunction 5560 cygwin_exception::open_stackdumpfile: Dumping stack trace to myFunction.exe.stackdump

The contents of stackdump file are as follows:

Stack trace:
Frame        Function    Args
00000223800  0018006FB93 (0060007AE38, 00600083EC8, 00600083EF8, 00600083F28)
00000000006  0018007105A (0060007BB78, 00600000000, 0000000014C, 00000000000)
000002239E0  0018011C6A7 (00600083048, 00600083078, 006000830A8, 006000830D8)
00000000041  001801198DE (0060007DCB8, 0060007DCE8, 00000000000, 0060007DD48)
0060008F2B0  00180119DAB (0060007E1F8, 0060007E228, 0060007E258, 00000000006)
0060008F2B0  00180119F7C (0060007CB38, 0060007CB68, 0060007CB98, 0060007CBC8)
0060008F2B0  0018011A23F (00180115A0B, 0060007CCE8, 006000885B0, 00000000000)
0060008F2B0  00180148A65 (003FC4AA93D, 00600083900, 00100439102, 0060007B080)
0060008F2B0  001800C1DB3 (00000000000, 00000223EE0, 0010042A2BC, 00000223E90)
0060008F2B0  00180115A0B (00000223EE0, 0010042A2BC, 00000223E90, 00000000017)
0060008F2B0  00600000001 (00000223EE0, 0010042A2BC, 00000223E90, 00000000017)
End of stack trace

Let me describe in detail the peculiar problem which happens at runtime. I am not able to describe the problem with just words, so I am listing scenario when the program works and when it fails.

I have created a vector of string in my header file and initialised them in the constructor as follows :

std::vector <std::string> symbolMap,localSymbolMap;

for(int i=0;i<100;i++){
    symbolMap.push_back(" ");
    localSymbolMap.push_back(" ");
}

I have defined a function to assign appropriate value to these variables later in the program as follows :

void TestClient::setTickerMap(int j, std::string symbol, std::string localSymbol){

symbolMap[j] = symbol;
localSymbolMap[j]=localSymbol;
}

Now, in the main program, I call this function as follows:

TestClient client;
for(int j=0;j<27;j++){
std::cout<<j<<" "<<realTimeSymbols[j]<<" "<<getLocalSymbol(realTimeSymbols[j],date)<<std::endl;    

client.setTickerMap(j,realTimeSymbols[j],getLocalSymbol(realTimeSymbols[j],date)); } // Here, I have checked for each j, that values of realTimeSymbols and getLocalSymbol are proper.

When I run the program, I get the error described above. The program always crashed when j is equal to 24.

Now the following workaround is working as of now:

void TestClient ::setTickerMap(int j, std::string symbol, std::string localSymbol){
    if(j==24){
//      symbolMap[j]="SYNDIBANK";
//      localSymbolMap[j]="SYNDIBANK15MARFUT";
    }
    else{
    symbolMap[j] = symbol;
    localSymbolMap[j]=localSymbol;
    }
    if(j==1){
        symbolMap[24]="SYNDIBANK";
        localSymbolMap[24]="SYNDIBANK15MARFUT";
    }
}

Following 3 variations of the code are above workaround are not working and they result in the original error:

Variation 1:

void TestClient ::setTickerMap(int j, std::string symbol, std::string localSymbol){
    if(j==24){
//      symbolMap[j]="SYNDIBANK";
//      localSymbolMap[j]="SYNDIBANK15MARFUT";
    }
    else{
    symbolMap[j] = symbol;
    localSymbolMap[j]=localSymbol;
    }
    if(j==25){
        symbolMap[24]="SYNDIBANK";
        localSymbolMap[24]="SYNDIBANK15MARFUT";
    }
}

Variation 2:

void TestClient ::setTickerMap(int j, std::string symbol, std::string localSymbol){
    if(j==24){
        symbolMap[j]="SYNDIBANK";
        localSymbolMap[j]="SYNDIBANK15MARFUT";
    }
    else{
    symbolMap[j] = symbol;
    localSymbolMap[j]=localSymbol;
    }
}

Variation 3:

void TestClient ::setTickerMap(int j, std::string symbol, std::string localSymbol){
    if(j==24){
        symbolMap[j]="AB";
        localSymbolMap[j]="SYNDIBANK15MARFUT";
    }
    else{
    symbolMap[j] = symbol;
    localSymbolMap[j]=localSymbol;
    }
}

Now, if I assign a single character to symbolMap in variation 3 as follows :

 symbolMap[j]="A";

then the code is able to run(although is the result is not correct).

I am not able to figure what exactly is causing this runtime error. I have checked the related question (Cygwin Exception : open stack dump file) and I do not have a separate session of cygwin running. I have restarted my PC just be extra sure. Still the problem persists. Any suggestions as to why this behaviour is seen on my PC.

UPDATE: To be sure that the error is not related to out-of-index, the following call from main program works fine:

    TestClient client;
    for(int j=25;j<27;j++){
    std::cout<<j<<" "<<realTimeSymbols[j]<<" "<<getLocalSymbol(realTimeSymbols[j],date)<<std::endl;    
  client.setTickerMap(j,realTimeSymbols[j],getLocalSymbol(realTimeSymbols[j],date));
    }

The program also works fine when j is iterated from 24 to 27. But fails when the loop is iterated from any number before 24 to 27.

GDB OUTPUT I do not have much experience with gdb but following is the output of the gdb if it helps:

GNU gdb (GDB) 7.8
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-cygwin".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from order_trading2632_limit.exe...done.
(gdb) run
Starting program: /cygdrive/e/eclipse_workspace/testClient/Debug/testClient.exe
[New Thread 4832.0x11e4]
[New Thread 4832.0x1798]
Attempt 1 of 10000
[New Thread 4832.0x1020]
Connection successful

Program received signal SIGABRT, Aborted.
0x00000003fc4ab0e3 in cygstdc++-6!_ZNSs6assignERKSs () from /usr/bin/cygstdc++-6.dll
(gdb) bt
#0  0x00000003fc4ab0e3 in cygstdc++-6!_ZNSs6assignERKSs () from /usr/bin/cygstdc++-6.dll
#1  0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
(gdb) set $pc=*(void **)$rsp
(gdb) set $rsp=$rsp+8
(gdb) bt
#0  0x000007fefd3110ac in WaitForSingleObjectEx () from /cygdrive/c/Windows/system32/KERNELBASE.dll
#1  0x000000018011c639 in sig_send(_pinfo*, siginfo_t&, _cygtls*) () from /usr/bin/cygwin1.dll
#2  0x00000001801198de in _pinfo::kill(siginfo_t&) () from /usr/bin/cygwin1.dll
#3  0x0000000180119dab in kill0(int, siginfo_t&) () from /usr/bin/cygwin1.dll
#4  0x0000000180119f7c in raise () from /usr/bin/cygwin1.dll
#5  0x000000018011a23f in abort () from /usr/bin/cygwin1.dll
#6  0x0000000180148a65 in dlfree () from /usr/bin/cygwin1.dll
#7  0x00000001800c1db3 in free () from /usr/bin/cygwin1.dll
#8  0x0000000180115a0b in _sigfe () from /usr/bin/cygwin1.dll
#9  0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Note that stack trace is corrupted and I have used trick from following question to print the stacktrace (GDB corrupted stack frame - How to debug?). Please help me in debugging the program further.

UPDATE

It is not the case that the error happens only when index is 24. Before calling the said loop, I initialize various arrays of int, double and string. Changing the number of initialization affects the index when this error happens. Today, I initialised vectors of length 24 before running this loop, this time the error happened at index 3.

This is really frustrating to implement the workaround. I do not that if there are some other memory issues I am overlooking because of this. Please offer suggestions.

CODE

int main(int argc, char** argv) {
    unsigned int port = 7900;
    const char* host = "";
    int clientId = 6;
    int attempt = 0;
    int MAX_ATTEMPTS=10000;
     int NUMREALTIMESYMBOLS=37;
     std::string realTimeSymbolsArr[]={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","aa","bb","cc","dd","ee","ff","gg","hh","ii","jj","kk"};
     std::vector <std::string> realTimeSymbols(realTimeSymbolsArr,realTimeSymbolsArr+NUMREALTIMESYMBOLS);
     int isTradeable[]={1,0,0,0,1,0,1,1,1,1,1,0,0,1,0,1,1,0,0,0,0,1,0,0,0,0,0,1,1,1,0,1,0,1,1,0,1};
     int numSubscriptions[]={2,2,1,4,1,1,2,6,3,1,1,1,2,1,3,1,1,2,1,3,1,1,1,10,4,1,6,1,1,9,4,2,1,3,1,1,2};
     int subscriptionList[NUMREALTIMESYMBOLS][100];
     int subscriptionIndex[NUMREALTIMESYMBOLS][100];
     subscriptionList[0][0]=0;subscriptionIndex[0][0]=0;
     subscriptionList[0][1]=2;subscriptionIndex[0][1]=2;
     subscriptionList[1][0]=2;subscriptionIndex[1][0]=1;
     subscriptionList[1][1]=0;subscriptionIndex[1][1]=3;
     subscriptionList[2][0]=2;subscriptionIndex[2][0]=0;
     subscriptionList[3][0]=4;subscriptionIndex[3][0]=2;
     subscriptionList[3][1]=31;subscriptionIndex[3][1]=2;
     subscriptionList[3][2]=13;subscriptionIndex[3][2]=3;
     subscriptionList[3][3]=34;subscriptionIndex[3][3]=3;
     subscriptionList[4][0]=4;subscriptionIndex[4][0]=0;
     subscriptionList[5][0]=9;subscriptionIndex[5][0]=2;
     subscriptionList[6][0]=6;subscriptionIndex[6][0]=0;
     subscriptionList[6][1]=8;subscriptionIndex[6][1]=2;
     subscriptionList[7][0]=7;subscriptionIndex[7][0]=0;
     subscriptionList[7][1]=8;subscriptionIndex[7][1]=1;
     subscriptionList[7][2]=31;subscriptionIndex[7][2]=1;
     subscriptionList[7][3]=36;subscriptionIndex[7][3]=1;
     subscriptionList[7][4]=13;subscriptionIndex[7][4]=2;
     subscriptionList[7][5]=34;subscriptionIndex[7][5]=2;
     subscriptionList[8][0]=8;subscriptionIndex[8][0]=0;
     subscriptionList[8][1]=7;subscriptionIndex[8][1]=1;
     subscriptionList[8][2]=21;subscriptionIndex[8][2]=3;
     subscriptionList[9][0]=9;subscriptionIndex[9][0]=0;
     subscriptionList[10][0]=10;subscriptionIndex[10][0]=0;
     subscriptionList[11][0]=11;subscriptionIndex[11][0]=0;
     subscriptionList[12][0]=28;subscriptionIndex[12][0]=3;
     subscriptionList[12][1]=33;subscriptionIndex[12][1]=3;
     subscriptionList[13][0]=13;subscriptionIndex[13][0]=0;
     subscriptionList[14][0]=33;subscriptionIndex[14][0]=1;
     subscriptionList[14][1]=28;subscriptionIndex[14][1]=2;
     subscriptionList[14][2]=15;subscriptionIndex[14][2]=3;
     subscriptionList[15][0]=15;subscriptionIndex[15][0]=0;
     subscriptionList[16][0]=16;subscriptionIndex[16][0]=0;
     subscriptionList[17][0]=0;subscriptionIndex[17][0]=1;
     subscriptionList[17][1]=11;subscriptionIndex[17][1]=2;
     subscriptionList[18][0]=7;subscriptionIndex[18][0]=2;
     subscriptionList[19][0]=6;subscriptionIndex[19][0]=3;
     subscriptionList[19][1]=8;subscriptionIndex[19][1]=3;
     subscriptionList[19][2]=16;subscriptionIndex[19][2]=3;
     subscriptionList[20][0]=9;subscriptionIndex[20][0]=1;
     subscriptionList[21][0]=21;subscriptionIndex[21][0]=0;
     subscriptionList[22][0]=9;subscriptionIndex[22][0]=3;
     subscriptionList[23][0]=6;subscriptionIndex[23][0]=1;
     subscriptionList[23][1]=10;subscriptionIndex[23][1]=1;
     subscriptionList[23][2]=27;subscriptionIndex[23][2]=1;
     subscriptionList[23][3]=29;subscriptionIndex[23][3]=1;
     subscriptionList[23][4]=16;subscriptionIndex[23][4]=2;
     subscriptionList[23][5]=21;subscriptionIndex[23][5]=2;
     subscriptionList[23][6]=2;subscriptionIndex[23][6]=3;
     subscriptionList[23][7]=4;subscriptionIndex[23][7]=3;
     subscriptionList[23][8]=7;subscriptionIndex[23][8]=3;
     subscriptionList[23][9]=36;subscriptionIndex[23][9]=3;
     subscriptionList[24][0]=24;subscriptionIndex[24][0]=0;
     subscriptionList[24][1]=24;subscriptionIndex[24][1]=1;
     subscriptionList[24][2]=24;subscriptionIndex[24][2]=2;
     subscriptionList[24][3]=24;subscriptionIndex[24][3]=3;
     subscriptionList[25][0]=29;subscriptionIndex[25][0]=3;
     subscriptionList[26][0]=21;subscriptionIndex[26][0]=1;
     subscriptionList[26][1]=0;subscriptionIndex[26][1]=2;
     subscriptionList[26][2]=10;subscriptionIndex[26][2]=2;
     subscriptionList[26][3]=15;subscriptionIndex[26][3]=2;
     subscriptionList[26][4]=27;subscriptionIndex[26][4]=2;
     subscriptionList[26][5]=33;subscriptionIndex[26][5]=2;
     subscriptionList[27][0]=27;subscriptionIndex[27][0]=0;
     subscriptionList[28][0]=28;subscriptionIndex[28][0]=0;
     subscriptionList[29][0]=29;subscriptionIndex[29][0]=0;
     subscriptionList[29][1]=4;subscriptionIndex[29][1]=1;
     subscriptionList[29][2]=13;subscriptionIndex[29][2]=1;
     subscriptionList[29][3]=16;subscriptionIndex[29][3]=1;
     subscriptionList[29][4]=34;subscriptionIndex[29][4]=1;
     subscriptionList[29][5]=6;subscriptionIndex[29][5]=2;
     subscriptionList[29][6]=36;subscriptionIndex[29][6]=2;
     subscriptionList[29][7]=27;subscriptionIndex[29][7]=3;
     subscriptionList[29][8]=31;subscriptionIndex[29][8]=3;
     subscriptionList[30][0]=30;subscriptionIndex[30][0]=0;
     subscriptionList[30][1]=30;subscriptionIndex[30][1]=1;
     subscriptionList[30][2]=30;subscriptionIndex[30][2]=2;
     subscriptionList[30][3]=30;subscriptionIndex[30][3]=3;
     subscriptionList[31][0]=31;subscriptionIndex[31][0]=0;
     subscriptionList[31][1]=29;subscriptionIndex[31][1]=2;
     subscriptionList[32][0]=11;subscriptionIndex[32][0]=3;
     subscriptionList[33][0]=33;subscriptionIndex[33][0]=0;
     subscriptionList[33][1]=15;subscriptionIndex[33][1]=1;
     subscriptionList[33][2]=28;subscriptionIndex[33][2]=1;
     subscriptionList[34][0]=34;subscriptionIndex[34][0]=0;
     subscriptionList[35][0]=11;subscriptionIndex[35][0]=1;
     subscriptionList[36][0]=36;subscriptionIndex[36][0]=0;
     subscriptionList[36][1]=10;subscriptionIndex[36][1]=3;
     double a1[]={720,0.0,750,0.0,900,0.0,760,360,120,390,600,360,0.0,760,0.0,140,660,0.0,0.0,0.0,0.0,720,0.0,0.0,100,0.0,0.0,120,320,40,100,500,0.0,630,570,0.0,100};
     double a2[]={0.5,0.0,1.3,0.0,0.6,0.0,0.45,0.15,0.45,0.4,0.25,1.4,0.0,0.55,0.0,0.2,0.8,0.0,0.0,0.0,0.0,0.6,0.0,0.0,0.4,0.0,0.0,0.25,0.4,0.25,0.4,0.35,0.0,0.4,0.5,0.0,0.4};
     double a3[]={1350,0.0,1250,0.0,300,0.0,1150,1400,900,1200,850,900,0.0,600,0.0,1450,1450,0.0,0.0,0.0,0.0,1000,0.0,0.0,1200,0.0,0.0,1150,350,1400,1200,1350,0.0,1500,300,0.0,1200};
     double a4[]={0.6,0.0,0.7,0.0,0.2,0.0,0.3,0.55,0.4,0.8,0.25,0.7,0.0,0.25,0.0,0.55,0.5,0.0,0.0,0.0,0.0,0.4,0.0,0.0,0.7,0.0,0.0,0.65,0.55,0.45,0.7,0.6,0.0,0.4,0.4,0.0,0.7};
     double a5[]={300,0.0,1300,0.0,1350,0.0,200,1100,1200,650,1500,1350,0.0,1050,0.0,1300,550,0.0,0.0,0.0,0.0,250,0.0,0.0,150,0.0,0.0,1250,700,1150,150,1250,0.0,1500,1500,0.0,150};
     double a6[]={0.3,0.0,0.8,0.0,0.6,0.0,0.5,0.6,0.6,0.3,0.35,0.7,0.0,0.55,0.0,0.45,0.35,0.0,0.0,0.0,0.0,0.3,0.0,0.0,0.5,0.0,0.0,0.55,0.3,0.35,0.5,0.75,0.0,0.2,0.5,0.0,0.5};
     double a7[]={1500,0.0,1500,0.0,1050,0.0,750,1100,1350,1350,100,1350,0.0,550,0.0,1400,1000,0.0,0.0,0.0,0.0,1000,0.0,0.0,1350,0.0,0.0,350,550,350,1350,500,0.0,1350,1250,0.0,1350};
     double a8[]={0.9,0.0,0.9,0.0,0.8,0.0,0.6,0.35,0.7,0.2,0.15,0.7,0.0,0.3,0.0,0.55,0.5,0.0,0.0,0.0,0.0,0,0.0,0.0,0.3,0.0,0.0,0.4,0.3,0.5,0.3,0.35,0.0,0.5,0.5,0.0,0.3};
     double a9[]={0.008,0.0,0.009,0.0,0.01,0.0,0.01,0.009,0.009,0.007,0.009,0.01,0.0,0.009,0.0,0.01,0.008,0.0,0.0,0.0,0.0,0.01,0.0,0.0,0.006,0.0,0.0,0.008,0.009,0.01,0.006,0.009,0.0,0.008,0.009,0.0,0.006};
     double a10[]={0.008,0.0,0.009,0.0,0.008,0.0,0.008,0.008,0.009,0.008,0.008,0.006,0.0,0.009,0.0,0.01,0.008,0.0,0.0,0.0,0.0,0.005,0.0,0.0,0.009,0.0,0.0,0.01,0.008,0.009,0.009,0.009,0.0,0.008,0.01,0.0,0.009};
     double a11[]={0.4,0.0,0.2,0.0,0.1,0.0,0.3,0.4,0.2,0.1,0.7,0.2,0.0,0,0.0,0.1,0,0.0,0.0,0.0,0.0,0.1,0.0,0.0,0.2,0.0,0.0,0.3,0,0.2,0.2,0,0.0,0.7,0.1,0.0,0.2};
     int a12[]={500,1000,8000,2000,4000,1000,1250,1000,1000,500,1000,125,2000,4000,1000,250,2000,250,1000,1250,500,2000,1000,500,0,250,500,4000,4000,1250,0,2000,500,500,4000,125,1000};
     double a13[]={0.0013406,0.0020022,0.0018709,0.0018948,0.0017975,0.0014687,0.0011068,0.001355,0.0010891,0.00088151,0.0014294,0.0012989,0.0014205,0.0019711,0.0015365,0.0020505,0.0018961,0.00078672,0.0023114,0.0012203,0.0012849,0.0015674,0.0012844,0.0014197,0.0,0.00074657,0.00096164,0.0017109,0.0015385,0.00068178,0.0,0.0021815,0.00087359,0.00074349,0.0021645,0.001595,0.0014573};
     int a14[]={14850,0,16500,0,13740,0,13740,24750,13740,14100,13740,30750,0,14400,0,13740,13740,0,0,0,0,14100,0,0,13500,0,0,13740,13740,25200,13500,13740,0,13740,13740,0,13740};
     int a15[]={30750,0,35900,0,34950,0,35900,35900,35900,35900,30000,34950,0,26250,0,34000,35900,0,0,0,0,34500,0,0,13500,0,0,35900,34650,35900,13500,32700,0,35900,35900,0,33300};
      Client client;
     for (int i = 0; i < MAX_ATTEMPTS; i++) {
        client.connect(host, port, clientId);
        ++attempt;
        std::cout << "Attempt " << attempt << " of " << MAX_ATTEMPTS<< std::endl;
        for (int j=0;j<NUMREALTIMESYMBOLS;j++){
            if(j==24 || j==30)
                continue;

            std::cout<<j<<" "<<realTimeSymbols[j]<<" "<<getLocalSymbol(realTimeSymbols[j],date)<<std::endl;
            client.setTickerMap(j,realTimeSymbols[j],getLocalSymbol(realTimeSymbols[j],date));
        }
    }
}

Constructor of Client:

 Client::Client(){
    for(int i=0;i<50;i++){
        symbolMap.push_back(" ");
        localSymbolMap.push_back(" ");
    }
}

The above code fails at 24 and 30. Hence, the loop to continue when j is 24 or 30 as workaround.

Community
  • 1
  • 1
lonstud
  • 525
  • 2
  • 19
  • tried running in gdb? That will help you pinpoint where your program is crashing. – jsantander Mar 16 '15 at 16:37
  • Try to link with indexing checking version of standard library, or replace `[i]` with `.at(i)` throughout, to find possible out-of-bounds indexing. – Cheers and hth. - Alf Mar 16 '15 at 16:37
  • @jsantander: I am not using gdb but I have checked with printf and fflush(stdout) to make sure the error happens when j is equal to 24. and during the assignment of symbolMap[j] inside setTickerMap function. – lonstud Mar 16 '15 at 16:42
  • @Alf. I have changed the code to .at(i), still the problem persists. I do not think this is an out-of-bounds indexing error. When I assign a single character to the symbolMap[j] when j==24, then the code works fine. Also, the workaound should have failed if it was out-of-indexing array. – lonstud Mar 16 '15 at 16:45
  • What happens if you change the arguments for `setTickerMap` from `std::string` to `const std::string&` ? – Matthew Moss Mar 20 '15 at 17:22
  • changed signature of setTickerMap from void setTickerMap(int j,std::string symbol, std::string localSymbol); to void setTickerMap(int j,const std::string& symbol, const std::string& localSymbol); . Still the error is same. – lonstud Mar 21 '15 at 05:42
  • You probably trashed the stack somewhere else and notice the consequences in the code above. Can you give the complete code including the initialization to other variables? An indicator for this is that the number of initializations affects the behavior. – user0815 Mar 22 '15 at 10:30
  • @user0815 added the code to the description. – lonstud Mar 23 '15 at 10:50
  • 3
    Three screenful of code, but nothing that I could actually compile to reproduce the error? That posted bounty inhibits a vote-to-close, or I would have voted so. Please rephrase your question to include a [MCVE](http://stackoverflow.com/help/mcve). *Preparing* such a minimal example is a time-honored debugging technique. – DevSolar Mar 23 '15 at 11:07
  • Thank you DevSolar for suggestion of creating MCVE. However, I have failed to create such an example which has a simple structure. My project consists of around 25 files. I tried to remove certain piece of code which removed the error. But then I removed other code and reintroduced the removed code and still no error. Some interaction between the code is leaving the program vulnerable to bug. Apologies for not being able to share the complete source code. – lonstud Mar 23 '15 at 15:17
  • The stack corruption appears to happen in getLocalSymbol(). You are somewhere writing beyond the bounds in any of your fields. – Ext3h Mar 24 '15 at 15:20
  • 1
    What you need is to provide a complete code sample that compiles and crashes. Meaning the main.cpp above, as well as a reduced version of the Client class. Then we can run the code, debug it, and easily find the error. – coyotte508 Mar 24 '15 at 15:37
  • @amitchaudhary If I'm reading the `subscriptionList` and `subscriptionIndex` right, then `[24][1]` to `[24][3]` and `[30][1]` to `[30][3]` are mapping to themselves, as where every other possible trace eventually maps to `[N][0]`. You have not corrupted your stack, but you have simply run out of stack space! Fix that endless recursion, and your application will run. – Ext3h Mar 24 '15 at 15:42

1 Answers1

1
std::string realTimeSymbolsArr[]={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","aa","bb","cc","dd","ee","ff","gg","hh","ii","jj","kk"};

subscriptionList[24][1]=24;subscriptionIndex[24][1]=1;
subscriptionList[24][2]=24;subscriptionIndex[24][2]=2;
subscriptionList[24][3]=24;subscriptionIndex[24][3]=3;

subscriptionList[30][1]=30;subscriptionIndex[30][1]=1;
subscriptionList[30][2]=30;subscriptionIndex[30][2]=2;
subscriptionList[30][3]=30;subscriptionIndex[30][3]=3;

You have not posted the source for getLocalSymbol, but I must assume that it also uses the same data and has a flow of the following form:

getLocalSymbol(a, b) {
    int i, j, old_i, old_j;
    std::string value;
    // Derive i and j from the parameters
    // ...
    // And build the String
    do {
            old_i = i;
            old_j = j;
            i = subscriptionList[old_i][old_j];
            j = subscriptionIndex[old_i][old_j];
            value += realTimeSymbolsArr[i];
    } while(j > 0);
    return value;
}

Got it right? That control flow, or something equivalent, appears to be part of it, either way.

This goes well for almost all values of i and j - except for the aforementioned values of 24 and 30 for i, and 1 to 3 for j.

With these values, i and j remain the same in every iteration and value becomes longer and longer, until eventually something breaks on the stack which overwrites both j (and thereby causes the loop to terminate) and corrupts value.

Either way, the std::string you returned is now corrupted as you exceeded some limit during that endless loop.

As for how to solve it, fix that infinite loop and fix your data.

For fixing the loop, limit the iteration count.

For fixing your data, well, now that you know why the data is causing the bug, you should be able to figure yourself how to fix it.

Remember, you have to fix BOTH. If you don't fix the data, you will get an unreasonable long return value. And if you don't fix the iteration limit, it will crash again as soon as someone repeats a similar mistake when updating the data.

Ext3h
  • 5,713
  • 17
  • 43