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:
parent
8e4891367e
commit
ececdb7913
@ -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
|
* Copyright (c) 1990, 1993
|
||||||
@ -37,7 +37,7 @@
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)memchr.c 8.1 (Berkeley) 6/4/93";
|
static char sccsid[] = "@(#)memchr.c 8.1 (Berkeley) 6/4/93";
|
||||||
#else
|
#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
|
||||||
#endif /* LIBC_SCCS and not lint */
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
@ -55,9 +55,10 @@ memchr(const void *s, int c, size_t n)
|
|||||||
|
|
||||||
if (n != 0) {
|
if (n != 0) {
|
||||||
const unsigned char *p = s;
|
const unsigned char *p = s;
|
||||||
|
const unsigned char cmp = c;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (*p++ == c)
|
if (*p++ == cmp)
|
||||||
return __UNCONST(p - 1);
|
return __UNCONST(p - 1);
|
||||||
} while (--n != 0);
|
} while (--n != 0);
|
||||||
}
|
}
|
||||||
|
@ -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
|
* Copyright (c) 1990, 1993
|
||||||
@ -34,7 +34,7 @@
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)index.c 8.1 (Berkeley) 6/4/93";
|
static char sccsid[] = "@(#)index.c 8.1 (Berkeley) 6/4/93";
|
||||||
#else
|
#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
|
||||||
#endif /* LIBC_SCCS and not lint */
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
@ -53,10 +53,11 @@ index(const char *p, int ch)
|
|||||||
strchr(const char *p, int ch)
|
strchr(const char *p, int ch)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
const char cmp = ch;
|
||||||
_DIAGASSERT(p != NULL);
|
_DIAGASSERT(p != NULL);
|
||||||
|
|
||||||
for (;; ++p) {
|
for (;; ++p) {
|
||||||
if (*p == ch) {
|
if (*p == cmp) {
|
||||||
/* LINTED const cast-away */
|
/* LINTED const cast-away */
|
||||||
return(__UNCONST(p));
|
return(__UNCONST(p));
|
||||||
}
|
}
|
||||||
|
@ -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
|
* Copyright (c) 1988, 1993
|
||||||
@ -34,7 +34,7 @@
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)rindex.c 8.1 (Berkeley) 6/4/93";
|
static char sccsid[] = "@(#)rindex.c 8.1 (Berkeley) 6/4/93";
|
||||||
#else
|
#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
|
||||||
#endif /* LIBC_SCCS and not lint */
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
@ -52,10 +52,10 @@ rindex(const char *p, int ch)
|
|||||||
strrchr(const char *p, int ch)
|
strrchr(const char *p, int ch)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
char *save, c;
|
char *save;
|
||||||
|
const char c = ch;
|
||||||
|
|
||||||
_DIAGASSERT(p != NULL);
|
_DIAGASSERT(p != NULL);
|
||||||
c = ch;
|
|
||||||
|
|
||||||
for (save = NULL;; ++p) {
|
for (save = NULL;; ++p) {
|
||||||
if (*p == c) {
|
if (*p == c) {
|
||||||
|
Loading…
Reference in New Issue
Block a user