[Gdal-dev] Assertion in .tab driver

Mateusz Loskot mateusz at loskot.net
Fri Jun 15 07:36:53 EDT 2007


Daniel wrote:
> If he got a crash it could very well  be the same problem since
> isspace expects input that can be represented as an unsigned char or
> EOF.
> 
> Looking at Microsofts documentation for isspace at:
> http://msdn2.microsoft.com/en-us/library/y13z34da(VS.80).aspx
> 
> "When used with a debug CRT library, isspace will display a CRT assert
> if passed a parameter that is not EOF or in the range of 0 through
> 0xFF. When used with a non-debug CRT library, isspace will use the
> parameter as an index into an array, with undefined results if the
> parameter is not EOF or in the range of 0 through 0xFF."

Daniel,

That's one of the reason why old C functions should be replaced with C++
and safe equivalents (see below).

> So this could very well cause a crash. I don't think that the correct
> solution is to use iswspace since the rest of the code can't handle
> wide chars anyway.

IMO, it is not.

Instead of old functions, it's much better to use ctype facet object
which serves information about char type characteristics for current
locale. The facet-based solution is wrapped with template function
from <locale> library:

// Test >127 character
const char c = 128;
bool space = std::isspace<char>(c, std::locale()));


After we migrate to Unicode, we can easily switch to wide characters

std::isspace<wchar_t>(...)

but that's another story.

Cheers
-- 
Mateusz Loskot
http://mateusz.loskot.net



More information about the Gdal-dev mailing list