Module Name:    src
Committed By:   christos
Date:           Sat Apr 11 21:42:16 UTC 2009

Modified Files:
        src/lib/libc/string: memrchr.c

Log Message:
make this work properly, by moving to the end of the buffer before starting
the search.
remove clauses 3 + 4.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libc/string/memrchr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/memrchr.c
diff -u src/lib/libc/string/memrchr.c:1.1 src/lib/libc/string/memrchr.c:1.2
--- src/lib/libc/string/memrchr.c:1.1	Fri Apr 10 19:13:38 2009
+++ src/lib/libc/string/memrchr.c	Sat Apr 11 17:42:16 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: memrchr.c,v 1.1 2009/04/10 23:13:38 christos Exp $	*/
+/*	$NetBSD: memrchr.c,v 1.2 2009/04/11 21:42:16 christos Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -15,13 +15,6 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *        This product includes software developed by the NetBSD
- *        Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -37,7 +30,7 @@
  */
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: memrchr.c,v 1.1 2009/04/10 23:13:38 christos Exp $");
+__RCSID("$NetBSD: memrchr.c,v 1.2 2009/04/11 21:42:16 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include <assert.h>
@@ -49,12 +42,12 @@
 	_DIAGASSERT(s != NULL);
 
 	if (n != 0) {
-		const unsigned char *p = s;
+		const unsigned char *p = (const unsigned char *)s + n;
 		const unsigned char cmp = c;
 
 		do {
-			if (*p-- == cmp)
-				return __UNCONST(p + 1);
+			if (*--p == cmp)
+				return __UNCONST(p);
 		} while (--n != 0);
 	}
 	return NULL;

Reply via email to