When passing char (or unsigned char) arguments as int, assign them to a

temporary char (resp. unsigned char) before comparing, to force truncation
to the proper domain. This makes the coresponding regression tests succeed.
This commit is contained in:
martin 2008-01-08 21:57:06 +00:00
parent 8e4891367e
commit ececdb7913
3 changed files with 12 additions and 10 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: memchr.c,v 1.2 2007/06/04 18:19:27 christos Exp $ */
/* $NetBSD: memchr.c,v 1.3 2008/01/08 21:57:06 martin Exp $ */
/*-
* Copyright (c) 1990, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)memchr.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: memchr.c,v 1.2 2007/06/04 18:19:27 christos Exp $");
__RCSID("$NetBSD: memchr.c,v 1.3 2008/01/08 21:57:06 martin Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@ -55,9 +55,10 @@ memchr(const void *s, int c, size_t n)
if (n != 0) {
const unsigned char *p = s;
const unsigned char cmp = c;
do {
if (*p++ == c)
if (*p++ == cmp)
return __UNCONST(p - 1);
} while (--n != 0);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: strchr.c,v 1.2 2007/06/04 18:19:27 christos Exp $ */
/* $NetBSD: strchr.c,v 1.3 2008/01/08 21:57:06 martin Exp $ */
/*-
* Copyright (c) 1990, 1993
@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)index.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: strchr.c,v 1.2 2007/06/04 18:19:27 christos Exp $");
__RCSID("$NetBSD: strchr.c,v 1.3 2008/01/08 21:57:06 martin Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@ -53,10 +53,11 @@ index(const char *p, int ch)
strchr(const char *p, int ch)
#endif
{
const char cmp = ch;
_DIAGASSERT(p != NULL);
for (;; ++p) {
if (*p == ch) {
if (*p == cmp) {
/* LINTED const cast-away */
return(__UNCONST(p));
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: strrchr.c,v 1.3 2007/06/04 18:19:28 christos Exp $ */
/* $NetBSD: strrchr.c,v 1.4 2008/01/08 21:57:06 martin Exp $ */
/*
* Copyright (c) 1988, 1993
@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)rindex.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: strrchr.c,v 1.3 2007/06/04 18:19:28 christos Exp $");
__RCSID("$NetBSD: strrchr.c,v 1.4 2008/01/08 21:57:06 martin Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@ -52,10 +52,10 @@ rindex(const char *p, int ch)
strrchr(const char *p, int ch)
#endif
{
char *save, c;
char *save;
const char c = ch;
_DIAGASSERT(p != NULL);
c = ch;
for (save = NULL;; ++p) {
if (*p == c) {