[tor-commits] [tlsdate/master] Cast char to unsigned char before passing to ctype(3) isXYZ.

ioerror at torproject.org ioerror at torproject.org
Fri Apr 19 04:11:44 UTC 2013


commit 6b7041dbaf46d3fdff5a7cadccf8a99bf9bfe779
Author: Taylor R Campbell <campbell at mumble.net>
Date:   Wed Apr 17 21:04:33 2013 +0000

    Cast char to unsigned char before passing to ctype(3) isXYZ.
    
    The ctype(3) routines take an int, but the only valid arguments are
    EOF and values representable as unsigned char.  This is what you get
    out of, e.g., getc(3), but an arbitrary value of type char is not OK
    because negative values will lead to nasal demons.  Converting an
    arbitrary value of type char to unsigned char is OK, since then we
    have only non-negative values, and casting that to int makes it
    clearer what's going on.
---
 src/conf.c           |    2 +-
 src/tlsdate-helper.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/conf.c b/src/conf.c
index 3b50ea3..b093676 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -31,7 +31,7 @@ void strip_newlines(char *line)
 
 char *eat_whitespace(char *line)
 {
-  while (isspace(*line))
+  while (isspace((int)(unsigned char)*line))
     line++;
   return line;
 }
diff --git a/src/tlsdate-helper.c b/src/tlsdate-helper.c
index 4c5c6ca..3e85bed 100644
--- a/src/tlsdate-helper.c
+++ b/src/tlsdate-helper.c
@@ -122,7 +122,7 @@ static void
 validate_proxy_port(const char *port)
 {
   while (*port)
-    if (!isdigit(*port++))
+    if (!isdigit((int)(unsigned char)*port++))
       die("invalid char in port\n");
 }
 





More information about the tor-commits mailing list