diff options
author | Anton Lundin <glance@acc.umu.se> | 2014-07-10 21:37:29 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-07-10 12:44:51 -0700 |
commit | 6b4dd8d597f4aa52599305dfaf5af19054b4422c (patch) | |
tree | 6179e4e59a8404f949d8957d4cab7fb183457459 /save-xml.c | |
parent | 9b8c1e195aae87a61bf9faf51e8b13e9a349094c (diff) | |
download | subsurface-6b4dd8d597f4aa52599305dfaf5af19054b4422c.tar.gz |
Don't trust isspace() unless isascii() approves
We have seen isspace(0xC3) return true on windows so we need to do
something about this.
As a wise man said:
Using "isspace()" and friends on anything but the 0-127 range is just
fraught with danger, regardless of platform.
We remedy this by checking that isascii() says that its a 7-bit ascii
character, something isspace() knows how to handle
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'save-xml.c')
-rw-r--r-- | save-xml.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/save-xml.c b/save-xml.c index 9c802b82a..0a76753c6 100644 --- a/save-xml.c +++ b/save-xml.c @@ -35,12 +35,15 @@ static void show_utf8(struct membuffer *b, const char *text, const char *pre, co if (!text) return; /* remove leading and trailing space */ - while (isspace(*text)) + /* We need to combine isascii() with isspace(), + * because we can only trust isspace() with 7-bit ascii, + * on windows for example */ + while (isascii(*text) && isspace(*text)) text++; len = strlen(text); if (!len) return; - while (len && isspace(text[len - 1])) + while (len && isascii(text[len - 1]) && isspace(text[len - 1])) len--; /* strndup would be easier, but that doesn't appear to exist on Windows / Mac */ cleaned = strdup(text); |