[PATCH] lib: Use isspace on unsigned char

Volker Lendecke Volker.Lendecke at SerNet.DE
Mon Apr 27 06:18:38 MDT 2015


Hi!

This fixes bug 11223. Review&push appreciated.

Thanks,

Volker

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
-------------- next part --------------
From 5c37cc79ed28fb29152929b74361aa624557d9a1 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 26 Apr 2015 11:15:01 +0200
Subject: [PATCH] lib: Use isspace on unsigned char

Signed-off-by: Volker Lendecke <vl at samba.org>
Bug: https://bugzilla.samba.org/show_bug.cgi?id=11223
---
 lib/util/tini.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/lib/util/tini.c b/lib/util/tini.c
index 6cd301a..3bfc2d6 100644
--- a/lib/util/tini.c
+++ b/lib/util/tini.c
@@ -43,12 +43,21 @@
 #include <string.h>
 #include "tini.h"
 
+static bool c_isspace(char c)
+{
+	unsigned char uc = c;
+	if (c != uc) {
+		return false;
+	}
+	return isspace(uc);
+}
+
 static int next_content(FILE *f)
 {
 	int c;
 
 	for (c = fgetc(f); c != EOF; c = fgetc(f)) {
-		if (!isspace(c)) {
+		if (!c_isspace(c)) {
 			break;
 		}
 		if (c == '\n') {
@@ -145,7 +154,7 @@ next_line:
 			}
 
 			if ((pos > 1) && (buf[pos-2] == '\\') &&
-			    isspace(buf[pos-1])) {
+			    c_isspace(buf[pos-1])) {
 				/*
 				 * Line ends in "\ ". Mind that we zap
 				 * multiple spaces into one. Continuation.
@@ -160,7 +169,7 @@ next_line:
 			break;
 		}
 
-		if ((pos > 0) && isspace(buf[pos-1]) && isspace(c)) {
+		if ((pos > 0) && c_isspace(buf[pos-1]) && c_isspace(c)) {
 			/*
 			 * Zap multiple spaces to one
 			 */
@@ -203,14 +212,14 @@ static char *trim_one_space(char *buf)
 {
 	size_t len;
 
-	if (isspace(buf[0])) {
+	if (c_isspace(buf[0])) {
 		buf += 1;
 	}
 	len = strlen(buf);
 	if (len == 0) {
 		return buf;
 	}
-	if (isspace(buf[len-1])) {
+	if (c_isspace(buf[len-1])) {
 		buf[len-1] = '\0';
 	}
 
-- 
1.9.1



More information about the samba-technical mailing list