mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 23:43:24 +00:00
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>
This commit is contained in:
parent
9b8c1e195a
commit
6b4dd8d597
1 changed files with 5 additions and 2 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue