am 4f614a70: am e4ac8feb: Merge "libc: cleanup strchr"

* commit '4f614a7036b37480695884a4be3f3fe70188cd60':
  libc: cleanup strchr
This commit is contained in:
Nick Kralevich
2013-05-02 14:28:18 -07:00
committed by Android Git Automerger
4 changed files with 32 additions and 17 deletions

View File

@@ -66,7 +66,6 @@ libc_common_src_files := \
string/index.c \
string/strcasecmp.c \
string/strcat.c \
string/strchr.c \
string/strcspn.c \
string/strdup.c \
string/strlcat.c \
@@ -238,6 +237,7 @@ libc_bionic_src_files := \
bionic/signalfd.cpp \
bionic/sigwait.cpp \
bionic/__strcat_chk.cpp \
bionic/strchr.cpp \
bionic/__strcpy_chk.cpp \
bionic/strerror.cpp \
bionic/strerror_r.cpp \

View File

@@ -1,4 +1,3 @@
/* $OpenBSD: index.c,v 1.5 2005/08/08 08:05:37 espie Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
@@ -31,21 +30,21 @@
#include <string.h>
#include "libc_logging.h"
char *
__strchr_chk(const char *p, int ch, size_t s_len)
{
for (;; ++p, s_len--) {
if (s_len == 0)
__fortify_chk_fail("strchr read beyond buffer", 0);
if (*p == (char) ch)
return((char *)p);
if (!*p)
return((char *)NULL);
}
/* NOTREACHED */
extern "C" char* __strchr_chk(const char* p, int ch, size_t s_len) {
for (;; ++p, s_len--) {
if (__predict_false(s_len == 0)) {
__fortify_chk_fail("read beyond buffer", 0);
}
if (*p == static_cast<char>(ch)) {
return const_cast<char*>(p);
}
if (*p == '\0') {
return NULL;
}
}
/* NOTREACHED */
}
char *
strchr(const char *p, int ch) {
return __strchr_chk(p, ch, __BIONIC_FORTIFY_UNKNOWN_SIZE);
extern "C" char* strchr(const char* p, int ch) {
return __strchr_chk(p, ch, __BIONIC_FORTIFY_UNKNOWN_SIZE);
}