c++ - malloc(): memory corruption (fast), std::vector and std::stringstream -


so... got weird one. in following code, receive

*** error in `./a.out': malloc(): memory corruption (fast): 0x00000000011165f0 *** 

on while loop line of below function.

std::vector<std::string> stringsplitter(const std::string & tosplit, char split) {     std::stringstream stream(tosplit);     std::vector<std::string> toreturn;     std::string current;      while (std::getline(stream, current, split))         toreturn.push_back(current);      return toreturn; } 

i have been able reproduce error sending

send allenh1 passwd sup? 

but function works intended when send it

command allenh1 passwd room1 

any ideas?


the call function comes following lines in function:

   file * fssock = fdopen(fd, "r+");  // read character character until \n found or command string full.    while (commandlinelength < maxcommandline &&     read( fd, &newchar, 1) > 0 ) {      if (newchar == '\n' && prevchar == '\r') {         break;     }      commandline[ commandlinelength ] = newchar;     commandlinelength++;      prevchar = newchar; }  // add null character @ end of string // eliminate last \r commandlinelength--;     commandline[ commandlinelength ] = 0;  printf("received: %s\n", commandline);  std::string input(commandline); std::vector<std::string> byspace = stringsplitter(input, ' '); 

vector<string> split(string str, char delimiter) {   vector<string> internal;   stringstream ss(str); // turn string stream.   string tok;    while(getline(ss, tok, delimiter)) {     internal.push_back(tok);   }    return internal; } 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -