Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2004:
[Freeciv-Dev] (PR#10935) Fatal Freeciv Server Crash
Home

[Freeciv-Dev] (PR#10935) Fatal Freeciv Server Crash

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: lightning4@xxxxxxxxxxx, tomas.brukner@xxxxxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#10935) Fatal Freeciv Server Crash
From: "Vasco Alexandre da Silva Costa" <vasc@xxxxxxxxxxxxxx>
Date: Mon, 15 Nov 2004 18:04:52 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=10935 >

> [use_less - Mon Nov 08 04:27:05 2004]:
> 
> Here's a patch that casts the input to all the character functions in
> support.c to an unsigned char, then an int.  Could probably use more
> useful comments, though.

Here, I reimplemented ctype for you. :-)

Index: utility/support.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/support.c,v
retrieving revision 1.28
diff -u -u -r1.28 support.c
--- utility/support.c   17 May 2004 02:16:15 -0000      1.28
+++ utility/support.c   16 Nov 2004 02:04:15 -0000
@@ -517,7 +517,7 @@
 ***********************************************************************/
 bool my_isalnum(char c)
 {
-  return isalnum((int) c) != 0;
+  return (my_isalpha(c) || my_isdigit(c));
 }
 
 /**********************************************************************
@@ -525,7 +525,7 @@
 ***********************************************************************/
 bool my_isalpha(char c)
 {
-  return isalpha((int) c) != 0;
+  return (my_islower(c) || my_isupper(c));
 }
 
 /**********************************************************************
@@ -533,7 +533,15 @@
 ***********************************************************************/
 bool my_isdigit(char c)
 {
-  return isdigit((int) c) != 0;
+  return (c >= '0' && c <= '9');
+}
+
+/**********************************************************************
+  Wrapper function to work around broken libc implementations.
+***********************************************************************/
+bool my_islower(char c)
+{
+  return (c >= 'a' && c <= 'z');
 }
 
 /**********************************************************************
@@ -541,7 +549,7 @@
 ***********************************************************************/
 bool my_isprint(char c)
 {
-  return isprint((int) c) != 0;
+  return (c >= ' ' && c <= '~');
 }
 
 /**********************************************************************
@@ -549,7 +557,7 @@
 ***********************************************************************/
 bool my_isspace(char c)
 {
-  return isspace((int) c) != 0;
+  return (c == ' ' || (c >= '\t' && c <= '\r'));
 }
 
 /**********************************************************************
@@ -557,7 +565,7 @@
 ***********************************************************************/
 bool my_isupper(char c)
 {
-  return isupper((int) c) != 0;
+  return (c >= 'A' && c <= 'Z');
 }
 
 /**********************************************************************
@@ -565,7 +573,11 @@
 ***********************************************************************/
 char my_toupper(char c)
 {
-  return (char) toupper((int) c);
+  if (my_islower(c)) {
+    return (c - 'a' + 'A');
+  } else {
+    return c;
+  }
 }
 
 /**********************************************************************
@@ -573,5 +585,10 @@
 ***********************************************************************/
 char my_tolower(char c)
 {
-  return (char) tolower((int) c);
+  if (my_isupper(c)) {
+    return (c - 'A' + 'a');
+  } else {
+    return c;
+  }
 }
+
Index: utility/support.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/support.h,v
retrieving revision 1.19
diff -u -u -r1.19 support.h
--- utility/support.h   17 May 2004 02:16:15 -0000      1.19
+++ utility/support.h   16 Nov 2004 02:04:15 -0000
@@ -60,6 +60,7 @@
 bool my_isalnum(char c);
 bool my_isalpha(char c);
 bool my_isdigit(char c);
+bool my_islower(char c);
 bool my_isprint(char c);
 bool my_isspace(char c);
 bool my_isupper(char c);

[Prev in Thread] Current Thread [Next in Thread]