PDA

View Full Version : Is something wrong with strip_extra_spaces?



Asuna Yuuki Nagato
02-06-2024, 07:56 PM
In zq_strings.cpp we have:



// Don't actually use this to strip spaces.
char *strip_extra_spaces(char *string)


Why shouldn't I call this function? It is being called from void refresh in zquest.cpp, should we refactor that?

Asuna Yuuki Nagato
04-14-2024, 08:02 PM
One problem is that strip_extra_spaces does not check the return value of malloc.

Asuna Yuuki Nagato
04-14-2024, 08:05 PM
strlen is called many times in loops as well, no need to keep doing that if the length hasn't changed.

Asuna Yuuki Nagato
04-15-2024, 12:10 AM
Note that there is an overload of strip_extra_spaces taking a std::string&

The char* overload is called by MsgString in zq_strings.cpp, which allocates a 71 character array on the heap to pass to strip_extra_spaces. It's probably fine to allocate that on the stack instead.