[PATCH] Don't trust isspace() unless isascii() approves
Anton Lundin
glance at acc.umu.se
Thu Jul 10 12:37:29 PDT 2014
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 at acc.umu.se>
---
save-xml.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/save-xml.c b/save-xml.c
index 9c802b8..0a76753 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);
--
1.9.1
More information about the subsurface
mailing list