From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KzZka-0002dw-Dt for qemu-devel@nongnu.org; Mon, 10 Nov 2008 11:36:28 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KzZkY-0002dk-E5 for qemu-devel@nongnu.org; Mon, 10 Nov 2008 11:36:28 -0500 Received: from [199.232.76.173] (port=48156 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KzZkY-0002dh-5a for qemu-devel@nongnu.org; Mon, 10 Nov 2008 11:36:26 -0500 Received: from outbound-va3.frontbridge.com ([216.32.180.16]:64516 helo=VA3EHSOBE002.bigfish.com) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_ARCFOUR_MD5:16) (Exim 4.60) (envelope-from ) id 1KzZkX-00009c-8z for qemu-devel@nongnu.org; Mon, 10 Nov 2008 11:36:25 -0500 From: Christoph Egger Date: Mon, 10 Nov 2008 18:35:34 +0200 References: <200811101055.17281.Christoph.Egger@amd.com> In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="Boundary-00=_WLGGJAcy5N5scTD" Message-ID: <200811101735.34880.Christoph.Egger@amd.com> Subject: [Qemu-devel] Re: [PATCH] fix warnings on NetBSD Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Blue Swirl --Boundary-00=_WLGGJAcy5N5scTD Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On Monday 10 November 2008 17:03:27 Blue Swirl wrote: > On 11/10/08, Christoph Egger wrote: > > Hi! > > > > Attached patch fixes a series of this warning > > when compiling on NetBSD: > > > > warning: array subscript has type 'char' > > There has been some discussion on ctype.h macro problems, please see: > http://lists.gnu.org/archive/html/qemu-devel/2008-08/msg01239.html > > I'd vote for introducing qemu_isfoobar and qemu_towombat instead of casts. Attached patch introduces a CTYPE macro as mentioned on this mail. The diff in qemu-common.h has been taken from xen ioemu. Signed-off-by: Christoph Egger =2D-=20 AMD Saxony, Dresden, Germany Operating System Research Center Legal Information: AMD Saxony Limited Liability Company & Co. KG Sitz (Gesch=C3=A4ftsanschrift): Wilschdorfer Landstr. 101, 01109 Dresden, Deutschland Registergericht Dresden: HRA 4896 vertretungsberechtigter Komplement=C3=A4r: AMD Saxony LLC (Sitz Wilmington, Delaware, USA) Gesch=C3=A4ftsf=C3=BChrer der AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoy --Boundary-00=_WLGGJAcy5N5scTD Content-Type: text/x-diff; charset="utf-8"; name="qemu.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="qemu.diff" Index: readline.c =================================================================== --- readline.c (revision 5666) +++ readline.c (working copy) @@ -169,7 +169,7 @@ /* find first word (backwards) */ while (start > 0) { - if (!isspace(term_cmd_buf[start])) { + if (!CTYPE(isspace, term_cmd_buf[start])) { break; } @@ -178,7 +178,7 @@ /* find first space (backwards) */ while (start > 0) { - if (isspace(term_cmd_buf[start])) { + if (CTYPE(isspace, term_cmd_buf[start])) { ++start; break; } Index: block-vvfat.c =================================================================== --- block-vvfat.c (revision 5666) +++ block-vvfat.c (working copy) @@ -1056,7 +1056,7 @@ i = strrchr(dirname, ':') - dirname; assert(i >= 3); - if (dirname[i-2] == ':' && isalpha(dirname[i-1])) + if (dirname[i-2] == ':' && CTYPE(isalpha, dirname[i-1])) /* workaround for DOS drive names */ dirname += i-1; else Index: target-ppc/translate_init.c =================================================================== --- target-ppc/translate_init.c (revision 5666) +++ target-ppc/translate_init.c (working copy) @@ -9458,7 +9458,7 @@ p = name; check_pvr: for (i = 0; i < 8; i++) { - if (!isxdigit(*p++)) + if (!CTYPE(isxdigit, *p++)) break; } if (i == 8) Index: net.c =================================================================== --- net.c (revision 5666) +++ net.c (working copy) @@ -279,7 +279,7 @@ if (buf[0] == '\0') { saddr->sin_addr.s_addr = 0; } else { - if (isdigit(buf[0])) { + if (CTYPE(isdigit, buf[0])) { if (!inet_aton(buf, &saddr->sin_addr)) return -1; } else { Index: cutils.c =================================================================== --- cutils.c (revision 5666) +++ cutils.c (working copy) @@ -72,7 +72,7 @@ p = str; q = val; while (*q != '\0') { - if (toupper(*p) != toupper(*q)) + if (CTYPE(toupper, *p) != CTYPE(toupper, *q)) return 0; p++; q++; Index: audio/audio.c =================================================================== --- audio/audio.c (revision 5666) +++ audio/audio.c (working copy) @@ -215,7 +215,7 @@ pstrcat (r, len + sizeof (qemu_prefix), s); for (i = 0; i < len; ++i) { - u[i] = toupper (u[i]); + u[i] = CTYPE(toupper, u[i]); } } return r; @@ -470,7 +470,7 @@ /* copy while upper-casing, including trailing zero */ for (i = 0; i <= preflen; ++i) { - optname[i + sizeof (qemu_prefix) - 1] = toupper (prefix[i]); + optname[i + sizeof (qemu_prefix) - 1] = CTYPE(toupper, prefix[i]); } pstrcat (optname, optlen, "_"); pstrcat (optname, optlen, opt->name); Index: qemu-common.h =================================================================== --- qemu-common.h (revision 5666) +++ qemu-common.h (working copy) @@ -93,6 +93,17 @@ int stristart(const char *str, const char *val, const char **ptr); time_t mktimegm(struct tm *tm); +#define CTYPE(isfoobar,argumentchar) (isfoobar((unsigned char)(argumentchar))) + /* One must not pass a plain `char' to isupper, toupper, et al. If + * it has the top bit set (ie, is negative if your chars are + * signed), undefined behaviour results. The functions + * are defined to take the value of an unsigned char, as an int. + * So use this macro. You may pass toupper et al for isfoobar. + * Do not pass EOF as a character to this macro. If you might have + * EOF then you ought to have it in an int representing an unsigned + * char, which is safe for the ctype macros directly. Or test separately. + * Obviously don't use this for floating point things like isnan! */ + void *qemu_malloc(size_t size); void *qemu_realloc(void *ptr, size_t size); void *qemu_mallocz(size_t size); Index: monitor.c =================================================================== --- monitor.c (revision 5666) +++ monitor.c (working copy) @@ -1933,7 +1933,7 @@ { if (pch != '\0') { pch++; - while (isspace(*pch)) + while (CTYPE(isspace, *pch)) pch++; } } @@ -1992,7 +1992,7 @@ *q++ = *pch; pch++; } - while (isspace(*pch)) + while (CTYPE(isspace, *pch)) pch++; *q = 0; ret = get_monitor_def(®, buf); @@ -2017,7 +2017,7 @@ expr_error("invalid char in expression"); } pch = p; - while (isspace(*pch)) + while (CTYPE(isspace, *pch)) pch++; break; } @@ -2111,7 +2111,7 @@ *pp = pch; return -1; } - while (isspace(*pch)) + while (CTYPE(isspace, *pch)) pch++; *pval = expr_sum(); *pp = pch; @@ -2126,7 +2126,7 @@ q = buf; p = *pp; - while (isspace(*p)) + while (CTYPE(isspace, *p)) p++; if (*p == '\0') { fail: @@ -2171,7 +2171,7 @@ } p++; } else { - while (*p != '\0' && !isspace(*p)) { + while (*p != '\0' && !CTYPE(isspace, *p)) { if ((q - buf) < buf_size - 1) { *q++ = *p; } @@ -2217,12 +2217,12 @@ /* extract the command name */ p = cmdline; q = cmdname; - while (isspace(*p)) + while (CTYPE(isspace, *p)) p++; if (*p == '\0') return; pstart = p; - while (*p != '\0' && *p != '/' && !isspace(*p)) + while (*p != '\0' && *p != '/' && !CTYPE(isspace, *p)) p++; len = p - pstart; if (len > sizeof(cmdname) - 1) @@ -2258,7 +2258,7 @@ int ret; char *str; - while (isspace(*p)) + while (CTYPE(isspace, *p)) p++; if (*typestr == '?') { typestr++; @@ -2299,15 +2299,15 @@ { int count, format, size; - while (isspace(*p)) + while (CTYPE(isspace, *p)) p++; if (*p == '/') { /* format found */ p++; count = 1; - if (isdigit(*p)) { + if (CTYPE(isdigit, *p)) { count = 0; - while (isdigit(*p)) { + while (CTYPE(isdigit, *p)) { count = count * 10 + (*p - '0'); p++; } @@ -2346,7 +2346,7 @@ } } next: - if (*p != '\0' && !isspace(*p)) { + if (*p != '\0' && !CTYPE(isspace, *p)) { term_printf("invalid char in format: '%c'\n", *p); goto fail; } @@ -2380,7 +2380,7 @@ { int64_t val; - while (isspace(*p)) + while (CTYPE(isspace, *p)) p++; if (*typestr == '?' || *typestr == '.') { if (*typestr == '?') { @@ -2391,7 +2391,7 @@ } else { if (*p == '.') { p++; - while (isspace(*p)) + while (CTYPE(isspace, *p)) p++; has_arg = 1; } else { @@ -2436,7 +2436,7 @@ c = *typestr++; if (c == '\0') goto bad_type; - while (isspace(*p)) + while (CTYPE(isspace, *p)) p++; has_option = 0; if (*p == '-') { @@ -2461,7 +2461,7 @@ } } /* check that all arguments were parsed */ - while (isspace(*p)) + while (CTYPE(isspace, *p)) p++; if (*p != '\0') { term_printf("%s: extraneous characters at the end of line\n", @@ -2609,7 +2609,7 @@ p = cmdline; nb_args = 0; for(;;) { - while (isspace(*p)) + while (CTYPE(isspace, *p)) p++; if (*p == '\0') break; @@ -2643,7 +2643,7 @@ /* if the line ends with a space, it means we want to complete the next arg */ len = strlen(cmdline); - if (len > 0 && isspace(cmdline[len - 1])) { + if (len > 0 && CTYPE(isspace, cmdline[len - 1])) { if (nb_args >= MAX_ARGS) return; args[nb_args++] = qemu_strdup(""); --Boundary-00=_WLGGJAcy5N5scTD--