Memory corruption warning workaround
|Reported by:||wxBen||Owned by:|
I have been using the wxHtmlWindow and it works very nicely. However, with all possible debug and memory corruption and heap checks turned on, Visual Studio stops on the following lines and complains about heap corruption and you cannot continue on:
wxSscanf(wd.c_str(), wxT("%i"), &width);
Now I have been debugging this, and it is a surprisingly complex line, with lots of temporary objects with buffers and ref counts being created for example. Even though the heap does indeed seem to get corrupted, despite careful debugging and being in the one in our group who fixes memory corruption issues, I could not find any real cause for it.
However, if you look at other functions in the files in question, in several places it uses this:
with GetParamAsInt really just using wxString::ToLong and casting to an int with the return value being ignored really.
Likely that is not used in these cases as the param string value has already been extracted, and just needs to be converted to an int. But I think the cost of wxSscanf is considerably more than GetParamAsInt which is still more than you need here as well. The string is essentially just one number, nothing complex or multiple arguments being extracted or anything.
So the solution to this issue seems to be to simplify the code. So I replaced the lines in question with simpler equivalents. That seems to work and Visual Studio is no longer complaining about memory corruption on those lines.
Please carefully check and verify.