Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions basic/strdb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ void read_text(const char *file, int_func *func, StrDB &db, bool read_cached, bo
}
if(write_cached) logs("Writing to " << int_file);

char s[16384];
char buf[16384]; int buf_i = 0; // Output buffer
while(in >> s) { // Read a string
for(std::string line; getline( in, line, ' ');) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove extra space

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. To preserve 'breaking on whitespace functionality' the code can be modified as below.
    for(std::string line; getline(std::ws(in), line, ' ');)

  2. I think the reason why the previous code didn't work has got something to do with the internal memory allocation, buffer handling of the inputstream and copying to a char array of [16384] size. The recommended way to read is into a std::string rather than a char array. The stacktrace also seems to indicate that the internal memcpy operation didn't go fine.

I think an understanding beyond this may require me to dig deeper into the workings of the ifstream, limitations of reading via operator>> versus getline, and also into possibly libc library oeprations.

const char *s = line.c_str();
int a = db.lookup(s, incorp_new, -1);
if(func) func(a);

Expand Down