If a string address is NULL when civet tries to access it the sim crashes
|
static void write_quoted_str( std::ostream& os, const char* s) { |
|
int ii; |
|
int len = strlen(s); |
|
os << "\"" ; |
|
for (ii=0 ; ii<len ; ii++) { |
|
switch ((s)[ii]) { |
|
case '\n': os << "\\n"; break; |
|
case '\t': os << "\\t"; break; |
|
case '\b': os << "\\b"; break; |
|
case '\"': os << "\\\""; break; |
|
default : os << s[ii] ; break; |
|
} |
|
} |
|
os << "\"" ; |
|
} |
Crash output snippet:
Thread 4 (MyCivetServer web thread):
#0 __strlen_evex () from /lib64/libc.so.6
#1 write_quoted_str (os=..., s=0x0) at src/VariableServerVariable.cpp:62
#2 VariableServerVariable::writeValue (this=..., outs=...) at src/VariableServerVariable.cpp:188
#3 VariableServerSession::sendMessage (this=...) at src/VariableServerSession.cpp:82
#4 main_loop (S=...) at src/MyCivetServer.cpp:227
Suggested edit:
static void write_quoted_str( std::ostream& os, const char* s) {
// Return an empty string when s is NULL
if (!s) {
os << "\"\""; return;
}
int ii;
int len = strlen(s);
os << "\"" ;
for (ii=0 ; ii<len ; ii++) {
switch ((s)[ii]) {
case '\n': os << "\\n"; break;
case '\t': os << "\\t"; break;
case '\b': os << "\\b"; break;
case '\"': os << "\\\""; break;
default : os << s[ii] ; break;
}
}
os << "\"" ;
}
If a string address is NULL when civet tries to access it the sim crashes
trick/trick_source/web/CivetServer/src/VariableServerVariable.cpp
Lines 60 to 74 in 4a137dd
Crash output snippet:
Suggested edit: