[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/2] avoid compiler warnings regarding ctype functions
From: |
Eric Blake |
Subject: |
[PATCH 2/2] avoid compiler warnings regarding ctype functions |
Date: |
Wed, 3 Nov 2010 09:56:49 -0600 |
On cygwin prior to this patch, compilation with -Wall resulted in:
compile.c: In function `setup_replacement':
compile.c:809: warning: array subscript has type `char'
compile.c: In function `normalize_text':
compile.c:1524: warning: array subscript has type `char'
The basicdefs.h fix is purely a compiler workaround, since the
use of isdigit() is already guaranteed to be in range; but the
compile.c fix is a true bug of calling toupper() with undefined
results if *p sign extends.
* basicdefs.h (ISDIGIT): Avoid compiler warning on cygwin.
* sed/compile.c (normalize_text): Avoid undefined behavior.
---
ChangeLog | 3 +++
basicdefs.h | 4 ++--
sed/compile.c | 4 ++--
3 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 9194dc7..6465767 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2010-11-03 Eric Blake <address@hidden>
+ * basicdefs.h (ISDIGIT): Avoid compiler warning on cygwin.
+ * sed/compile.c (normalize_text): Avoid undefined behavior.
+
* sed/sed.c (includes): Supply missing header.
2010-11-01 Paolo Bonzini <address@hidden>
diff --git a/basicdefs.h b/basicdefs.h
index 72f7503..2e4fcb4 100644
--- a/basicdefs.h
+++ b/basicdefs.h
@@ -1,5 +1,5 @@
/* GNU SED, a batch stream editor.
- Copyright (C) 1998, 1999, 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2002, 2003, 2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -151,7 +151,7 @@ typedef unsigned long countT;
#undef ISPRINT
#define ISPRINT(c) (ISASCII (c) && isprint (c))
-#define ISDIGIT(c) (ISASCII (c) && isdigit (c))
+#define ISDIGIT(c) (ISASCII (c) && isdigit ((unsigned char) (c)))
#define ISALNUM(c) (ISASCII (c) && isalnum (c))
#define ISALPHA(c) (ISASCII (c) && isalpha (c))
#define ISCNTRL(c) (ISASCII (c) && iscntrl (c))
diff --git a/sed/compile.c b/sed/compile.c
index b842e1b..b2fb825 100644
--- a/sed/compile.c
+++ b/sed/compile.c
@@ -1,5 +1,5 @@
/* GNU SED, a batch stream editor.
- Copyright (C) 1989,90,91,92,93,94,95,98,99,2002,2003,2004,2005,2006,2008
+ Copyright (C)
1989,90,91,92,93,94,95,98,99,2002,2003,2004,2005,2006,2008,2010
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
@@ -1521,7 +1521,7 @@ normalize_text(buf, len, buftype)
case 'c':
if (++p < bufend)
{
- *q++ = toupper(*p) ^ 0x40;
+ *q++ = toupper((unsigned char) *p) ^ 0x40;
p++;
continue;
}
--
1.7.3.2