Kaynağa Gözat

* Added egg_is*()
ctype.h is*() functions are apparently unsafe unless recasted.


svn: 271

Bryan Drewery 22 yıl önce
ebeveyn
işleme
cdf31bde80
5 değiştirilmiş dosya ile 23 ekleme ve 14 silme
  1. 8 7
      src/compat/inet_aton.c
  2. 2 2
      src/compat/snprintf.c
  3. 5 5
      src/dcc.c
  4. 7 0
      src/eggdrop.h
  5. 1 0
      src/misc.c

+ 8 - 7
src/compat/inet_aton.c

@@ -7,8 +7,9 @@
 #include "inet_aton.h"
 
 #ifndef HAVE_ISASCII
-/* Let all checks succeed if we don't have isascii(). */
-#  define isascii(x)	1
+#  define inet_isascii(x) 1 /* Let checks succeed if we don't have isascii(). */
+#else
+#  define inet_isascii(x) egg_isascii(x)
 #endif
 
 #ifndef HAVE_INET_ATON
@@ -104,7 +105,7 @@ egg_inet_aton(cp, addr)
 		 * Values are specified as for C:
 		 * 0x=hex, 0=octal, isdigit=decimal.
 		 */
-		if (!isdigit(c))
+		if (!egg_isdigit(c))
 			goto ret_0;
 		base = 10;
 		if (c == '0') {
@@ -116,12 +117,12 @@ egg_inet_aton(cp, addr)
 		}
 		val = 0;
 		for (;;) {
-			if (isascii(c) && isdigit(c)) {
+			if (inet_isascii(c) && egg_isdigit(c)) {
 				val = (val * base) + (c - '0');
 				c = *++cp;
-			} else if (base == 16 && isascii(c) && isxdigit(c)) {
+			} else if (base == 16 && inet_isascii(c) && egg_isxdigit(c)) {
 				val = (val << 4) |
-					(c + 10 - (islower(c) ? 'a' : 'A'));
+					(c + 10 - (egg_islower(c) ? 'a' : 'A'));
 				c = *++cp;
 			} else
 				break;
@@ -143,7 +144,7 @@ egg_inet_aton(cp, addr)
 	/*
 	 * Check for trailing characters.
 	 */
-	if (c != '\0' && (!isascii(c) || !isspace(c)))
+	if (c != '\0' && (!inet_isascii(c) || !egg_isspace(c)))
 		goto ret_0;
 	/*
 	 * Concoct the address according to

+ 2 - 2
src/compat/snprintf.c

@@ -200,7 +200,7 @@ static void dopr(char *buffer, size_t maxlen, const char *format,
       }
       break;
     case DP_S_MIN:
-      if (isdigit(ch)) {
+      if (egg_isdigit(ch)) {
 	min = 10 * min + char_to_int(ch);
 	ch = *format++;
       } else if (ch == '*') {
@@ -218,7 +218,7 @@ static void dopr(char *buffer, size_t maxlen, const char *format,
 	state = DP_S_MOD;
       break;
     case DP_S_MAX:
-      if (isdigit(ch)) {
+      if (egg_isdigit(ch)) {
 	if (max < 0)
 	  max = 0;
 	max = 10 * max + char_to_int(ch);

+ 5 - 5
src/dcc.c

@@ -807,14 +807,14 @@ static void strip_mirc_codes(int flags, char *text)
       break;
     case 3:			/* mIRC colors? */
       if (flags & STRIP_COLOR) {
-	if (isdigit(text[1])) {	/* Is the first char a number? */
+	if (egg_isdigit(text[1])) {	/* Is the first char a number? */
 	  text += 2;		/* Skip over the ^C and the first digit */
-	  if (isdigit(*text))
+	  if (egg_isdigit(*text))
 	    text++;		/* Is this a double digit number? */
 	  if (*text == ',') {	/* Do we have a background color next? */
-	    if (isdigit(text[1]))
+	    if (egg_isdigit(text[1]))
 	      text += 2;	/* Skip over the first background digit */
-	    if (isdigit(*text))
+	    if (egg_isdigit(*text))
 	      text++;		/* Is it a double digit? */
 	  }
 	} else
@@ -845,7 +845,7 @@ static void strip_mirc_codes(int flags, char *text)
 	text++;
 	if (*text == '[') {
 	  text++;
-	  while ((*text == ';') || isdigit(*text))
+	  while ((*text == ';') || egg_isdigit(*text))
 	    text++;
 	  if (*text)
 	    text++;		/* also kill the following char */

+ 7 - 0
src/eggdrop.h

@@ -282,6 +282,13 @@ typedef u_32bit_t dword;
 #define debug3(x,a1,a2,a3)	putlog(LOG_DEBUG,"*",x,a1,a2,a3)
 #define debug4(x,a1,a2,a3,a4)	putlog(LOG_DEBUG,"*",x,a1,a2,a3,a4)
 
+/* These apparently are unsafe without recasting. */
+#define egg_isdigit(x)  isdigit((int)  (unsigned char) (x))
+#define egg_isxdigit(x) isxdigit((int) (unsigned char) (x))
+#define egg_isascii(x)  isascii((int)  (unsigned char) (x))
+#define egg_isspace(x)  isspace((int)  (unsigned char) (x))
+#define egg_islower(x)  islower((int)  (unsigned char) (x))
+
 /***********************************************************************/
 
 /* It's used in so many places, let's put it here */

+ 1 - 0
src/misc.c

@@ -11,6 +11,7 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <ctype.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include "chan.h"