CVS commit: src/common/lib/libc/string

2021-05-16 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 16 09:43:39 UTC 2021

Modified Files:
src/common/lib/libc/string: memmem.c

Log Message:
memmem: remove unreachable return statement


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/common/lib/libc/string/memmem.c

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

Modified files:

Index: src/common/lib/libc/string/memmem.c
diff -u src/common/lib/libc/string/memmem.c:1.3 src/common/lib/libc/string/memmem.c:1.4
--- src/common/lib/libc/string/memmem.c:1.3	Mon Oct 15 19:32:48 2018
+++ src/common/lib/libc/string/memmem.c	Sun May 16 09:43:39 2021
@@ -25,7 +25,7 @@
 #if 0
 __FBSDID("$FreeBSD: head/lib/libc/string/memmem.c 315468 2017-03-18 00:53:24Z emaste $");
 #else
-__RCSID("$NetBSD: memmem.c,v 1.3 2018/10/15 19:32:48 christos Exp $");
+__RCSID("$NetBSD: memmem.c,v 1.4 2021/05/16 09:43:39 rillig Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -63,7 +63,6 @@ static char *fourbyte_memmem(const unsig
 	for (h += 4, k -= 4; k; k--, hw = hw << 8 | *h++)
 		if (hw == nw) return __UNCONST(h - 4);
 	return hw == nw ? __UNCONST(h - 4) : 0;
-	return 0;
 }
 
 #define MAX(a,b) ((a)>(b)?(a):(b))



CVS commit: src/common/lib/libc/string

2021-04-18 Thread Simon Burge
Module Name:src
Committed By:   simonb
Date:   Mon Apr 19 01:12:10 UTC 2021

Modified Files:
src/common/lib/libc/string: memset2.c

Log Message:
Add CVS ID line.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/common/lib/libc/string/memset2.c

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

Modified files:

Index: src/common/lib/libc/string/memset2.c
diff -u src/common/lib/libc/string/memset2.c:1.9 src/common/lib/libc/string/memset2.c:1.10
--- src/common/lib/libc/string/memset2.c:1.9	Sat Apr 17 21:43:47 2021
+++ src/common/lib/libc/string/memset2.c	Mon Apr 19 01:12:10 2021
@@ -1,3 +1,5 @@
+/*	$NetBSD: memset2.c,v 1.10 2021/04/19 01:12:10 simonb Exp $	*/
+
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -29,7 +31,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: memset2.c,v 1.9 2021/04/17 21:43:47 mrg Exp $");
+__RCSID("$NetBSD: memset2.c,v 1.10 2021/04/19 01:12:10 simonb Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include 



CVS commit: src/common/lib/libc/string

2021-04-17 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sat Apr 17 21:43:47 UTC 2021

Modified Files:
src/common/lib/libc/string: memset2.c

Log Message:
avoid redefinition warning for __OPTIMIZE_SIZE__.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/common/lib/libc/string/memset2.c

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

Modified files:

Index: src/common/lib/libc/string/memset2.c
diff -u src/common/lib/libc/string/memset2.c:1.8 src/common/lib/libc/string/memset2.c:1.9
--- src/common/lib/libc/string/memset2.c:1.8	Sat Apr 17 08:06:58 2021
+++ src/common/lib/libc/string/memset2.c	Sat Apr 17 21:43:47 2021
@@ -29,7 +29,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: memset2.c,v 1.8 2021/04/17 08:06:58 simonb Exp $");
+__RCSID("$NetBSD: memset2.c,v 1.9 2021/04/17 21:43:47 mrg Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include 
@@ -47,7 +47,8 @@ __RCSID("$NetBSD: memset2.c,v 1.8 2021/0
 #include 
 #include 
 
-#define __OPTIMIZE_SIZE__	/* other code path is very broken */
+#undef __OPTIMIZE_SIZE__
+#define __OPTIMIZE_SIZE__ 1	/* other code path is very broken */
 
 #ifdef TEST
 #include 



CVS commit: src/common/lib/libc/string

2021-04-17 Thread Simon Burge
Module Name:src
Committed By:   simonb
Date:   Sat Apr 17 08:06:58 UTC 2021

Modified Files:
src/common/lib/libc/string: memset2.c

Log Message:
Use __register_t instead of uregister_t - this is available to all ports
and both userland and kernel.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/common/lib/libc/string/memset2.c

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

Modified files:

Index: src/common/lib/libc/string/memset2.c
diff -u src/common/lib/libc/string/memset2.c:1.7 src/common/lib/libc/string/memset2.c:1.8
--- src/common/lib/libc/string/memset2.c:1.7	Sat Apr 17 06:02:35 2021
+++ src/common/lib/libc/string/memset2.c	Sat Apr 17 08:06:58 2021
@@ -29,7 +29,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: memset2.c,v 1.7 2021/04/17 06:02:35 simonb Exp $");
+__RCSID("$NetBSD: memset2.c,v 1.8 2021/04/17 08:06:58 simonb Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include 
@@ -60,11 +60,9 @@ __RCSID("$NetBSD: memset2.c,v 1.7 2021/0
 #undef memset
 
 /*
- * Assume uregister_t is the widest non-synthetic unsigned type.
+ * Assume __register_t is the widest non-synthetic unsigned type.
  */
-typedef uregister_t memword_t;
-
-__CTASSERT((~(memword_t)0U >> 1) != ~(memword_t)0U);
+typedef __register_t memword_t;
 
 #ifdef BZERO
 static inline



CVS commit: src/common/lib/libc/string

2021-04-17 Thread Simon Burge
Module Name:src
Committed By:   simonb
Date:   Sat Apr 17 06:02:35 UTC 2021

Modified Files:
src/common/lib/libc/string: memset2.c

Log Message:
Cast the fill value to unsigned char so that the "fill" value used for
full-word fills isn't garbage.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/common/lib/libc/string/memset2.c

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

Modified files:

Index: src/common/lib/libc/string/memset2.c
diff -u src/common/lib/libc/string/memset2.c:1.6 src/common/lib/libc/string/memset2.c:1.7
--- src/common/lib/libc/string/memset2.c:1.6	Sat Apr 17 05:57:11 2021
+++ src/common/lib/libc/string/memset2.c	Sat Apr 17 06:02:35 2021
@@ -29,7 +29,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: memset2.c,v 1.6 2021/04/17 05:57:11 simonb Exp $");
+__RCSID("$NetBSD: memset2.c,v 1.7 2021/04/17 06:02:35 simonb Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include 
@@ -97,7 +97,7 @@ memset(void *addr, int c, size_t len)
 	 * The conditional at the end prevents GCC from complaing about
 	 * shift count >= width of type 
 	 */
-	fill = c;
+	fill = (unsigned char)c;
 	fill |= fill << 8;
 	fill |= fill << 16;
 	fill |= fill << (sizeof(c) < sizeof(fill) ? 32 : 0);



CVS commit: src/common/lib/libc/string

2021-04-16 Thread Simon Burge
Module Name:src
Committed By:   simonb
Date:   Sat Apr 17 05:57:11 UTC 2021

Modified Files:
src/common/lib/libc/string: memset2.c

Log Message:
Disable the larger/faster code path.  While the optimised code path was
indeed quicker, it nonetheless failed to actually fill all the requested
memory with the specified value much of the time if a non-aligned start
address was used.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/common/lib/libc/string/memset2.c

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

Modified files:

Index: src/common/lib/libc/string/memset2.c
diff -u src/common/lib/libc/string/memset2.c:1.5 src/common/lib/libc/string/memset2.c:1.6
--- src/common/lib/libc/string/memset2.c:1.5	Fri Mar  2 16:22:27 2012
+++ src/common/lib/libc/string/memset2.c	Sat Apr 17 05:57:11 2021
@@ -29,7 +29,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: memset2.c,v 1.5 2012/03/02 16:22:27 apb Exp $");
+__RCSID("$NetBSD: memset2.c,v 1.6 2021/04/17 05:57:11 simonb Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include 
@@ -47,6 +47,8 @@ __RCSID("$NetBSD: memset2.c,v 1.5 2012/0
 #include 
 #include 
 
+#define __OPTIMIZE_SIZE__	/* other code path is very broken */
+
 #ifdef TEST
 #include 
 #define _DIAGASSERT(a)		assert(a)



CVS commit: src/common/lib/libc/string

2020-01-29 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Jan 29 09:18:26 UTC 2020

Modified Files:
src/common/lib/libc/string: bcmp.c memcmp.c

Log Message:
Some boot blocks too big now, only compare in big chunks if !_STANDALONE.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/common/lib/libc/string/bcmp.c
cvs rdiff -u -r1.7 -r1.8 src/common/lib/libc/string/memcmp.c

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

Modified files:

Index: src/common/lib/libc/string/bcmp.c
diff -u src/common/lib/libc/string/bcmp.c:1.9 src/common/lib/libc/string/bcmp.c:1.10
--- src/common/lib/libc/string/bcmp.c:1.9	Mon Jan 27 22:22:03 2020
+++ src/common/lib/libc/string/bcmp.c	Wed Jan 29 09:18:26 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: bcmp.c,v 1.9 2020/01/27 22:22:03 ad Exp $	*/
+/*	$NetBSD: bcmp.c,v 1.10 2020/01/29 09:18:26 ad Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -63,7 +63,7 @@
 #if 0
 static char sccsid[] = "@(#)bcmp.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: bcmp.c,v 1.9 2020/01/27 22:22:03 ad Exp $");
+__RCSID("$NetBSD: bcmp.c,v 1.10 2020/01/29 09:18:26 ad Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -86,9 +86,11 @@ __RCSID("$NetBSD: bcmp.c,v 1.9 2020/01/2
 int
 bcmp(const void *s1, const void *s2, size_t n)
 {
-	const uintptr_t *b1, *b2;
 	const unsigned char *c1, *c2;
 
+#ifndef _STANDALONE
+	const uintptr_t *b1, *b2;
+
 	b1 = s1;
 	b2 = s2;
 
@@ -105,6 +107,10 @@ bcmp(const void *s1, const void *s2, siz
 
 	c1 = (const unsigned char *)b1;
 	c2 = (const unsigned char *)b2;
+#else
+	c1 = (const unsigned char *)s1;
+	c2 = (const unsigned char *)s2;
+#endif
 
 	if (n != 0) {
 		do {

Index: src/common/lib/libc/string/memcmp.c
diff -u src/common/lib/libc/string/memcmp.c:1.7 src/common/lib/libc/string/memcmp.c:1.8
--- src/common/lib/libc/string/memcmp.c:1.7	Mon Jan 27 22:22:03 2020
+++ src/common/lib/libc/string/memcmp.c	Wed Jan 29 09:18:26 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: memcmp.c,v 1.7 2020/01/27 22:22:03 ad Exp $	*/
+/*	$NetBSD: memcmp.c,v 1.8 2020/01/29 09:18:26 ad Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
 #if 0
 static char sccsid[] = "@(#)memcmp.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: memcmp.c,v 1.7 2020/01/27 22:22:03 ad Exp $");
+__RCSID("$NetBSD: memcmp.c,v 1.8 2020/01/29 09:18:26 ad Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -86,9 +86,11 @@ __RCSID("$NetBSD: memcmp.c,v 1.7 2020/01
 int
 memcmp(const void *s1, const void *s2, size_t n)
 {
-	const uintptr_t *b1, *b2;
 	const unsigned char *c1, *c2;
 
+#ifndef _STANDALONE
+	const uintptr_t *b1, *b2;
+
 	b1 = s1;
 	b2 = s2;
 
@@ -107,6 +109,10 @@ memcmp(const void *s1, const void *s2, s
 
 	c1 = (const unsigned char *)b1;
 	c2 = (const unsigned char *)b2;
+#else
+	c1 = (const unsigned char *)s1;
+	c2 = (const unsigned char *)s2;
+#endif
 
 	if (n != 0) {
 		do {



CVS commit: src/common/lib/libc/string

2020-01-27 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Mon Jan 27 22:22:03 UTC 2020

Modified Files:
src/common/lib/libc/string: bcmp.c memcmp.c

Log Message:
Drop the alignment check if __NO_STRICT_ALIGNMENT (x86, m68k, vax).


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/common/lib/libc/string/bcmp.c
cvs rdiff -u -r1.6 -r1.7 src/common/lib/libc/string/memcmp.c

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

Modified files:

Index: src/common/lib/libc/string/bcmp.c
diff -u src/common/lib/libc/string/bcmp.c:1.8 src/common/lib/libc/string/bcmp.c:1.9
--- src/common/lib/libc/string/bcmp.c:1.8	Mon Jan 27 22:13:39 2020
+++ src/common/lib/libc/string/bcmp.c	Mon Jan 27 22:22:03 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: bcmp.c,v 1.8 2020/01/27 22:13:39 ad Exp $	*/
+/*	$NetBSD: bcmp.c,v 1.9 2020/01/27 22:22:03 ad Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -63,7 +63,7 @@
 #if 0
 static char sccsid[] = "@(#)bcmp.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: bcmp.c,v 1.8 2020/01/27 22:13:39 ad Exp $");
+__RCSID("$NetBSD: bcmp.c,v 1.9 2020/01/27 22:22:03 ad Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -92,7 +92,10 @@ bcmp(const void *s1, const void *s2, siz
 	b1 = s1;
 	b2 = s2;
 
-	if uintptr_t)b1 | (uintptr_t)b2) & (sizeof(uintptr_t) - 1)) == 0) {
+#ifndef __NO_STRICT_ALIGNMENT
+	if uintptr_t)b1 | (uintptr_t)b2) & (sizeof(uintptr_t) - 1)) == 0)
+#endif
+	{
 		while (n >= sizeof(uintptr_t)) {
 			if (*b1++ != *b2++)
 return 1;

Index: src/common/lib/libc/string/memcmp.c
diff -u src/common/lib/libc/string/memcmp.c:1.6 src/common/lib/libc/string/memcmp.c:1.7
--- src/common/lib/libc/string/memcmp.c:1.6	Mon Jan 27 22:13:39 2020
+++ src/common/lib/libc/string/memcmp.c	Mon Jan 27 22:22:03 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: memcmp.c,v 1.6 2020/01/27 22:13:39 ad Exp $	*/
+/*	$NetBSD: memcmp.c,v 1.7 2020/01/27 22:22:03 ad Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
 #if 0
 static char sccsid[] = "@(#)memcmp.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: memcmp.c,v 1.6 2020/01/27 22:13:39 ad Exp $");
+__RCSID("$NetBSD: memcmp.c,v 1.7 2020/01/27 22:22:03 ad Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -92,7 +92,10 @@ memcmp(const void *s1, const void *s2, s
 	b1 = s1;
 	b2 = s2;
 
-	if uintptr_t)b1 | (uintptr_t)b2) & (sizeof(uintptr_t) - 1)) == 0) {
+#ifndef __NO_STRICT_ALIGNMENT
+	if uintptr_t)b1 | (uintptr_t)b2) & (sizeof(uintptr_t) - 1)) == 0)
+#endif
+	{
 		while (n >= sizeof(uintptr_t)) {
 			if (*b1 != *b2)
 break;



CVS commit: src/common/lib/libc/string

2020-01-27 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Mon Jan 27 22:13:39 UTC 2020

Modified Files:
src/common/lib/libc/string: bcmp.c memcmp.c

Log Message:
bcmp() / memcmp(): compare in uintptr_t sized chunks when it's easy to.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/common/lib/libc/string/bcmp.c
cvs rdiff -u -r1.5 -r1.6 src/common/lib/libc/string/memcmp.c

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

Modified files:

Index: src/common/lib/libc/string/bcmp.c
diff -u src/common/lib/libc/string/bcmp.c:1.7 src/common/lib/libc/string/bcmp.c:1.8
--- src/common/lib/libc/string/bcmp.c:1.7	Fri Mar  9 15:41:16 2012
+++ src/common/lib/libc/string/bcmp.c	Mon Jan 27 22:13:39 2020
@@ -1,4 +1,33 @@
-/*	$NetBSD: bcmp.c,v 1.7 2012/03/09 15:41:16 christos Exp $	*/
+/*	$NetBSD: bcmp.c,v 1.8 2020/01/27 22:13:39 ad Exp $	*/
+
+/*-
+ * Copyright (c) 2020 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Andrew Doran.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
 
 /*
  * Copyright (c) 1987, 1993
@@ -34,7 +63,7 @@
 #if 0
 static char sccsid[] = "@(#)bcmp.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: bcmp.c,v 1.7 2012/03/09 15:41:16 christos Exp $");
+__RCSID("$NetBSD: bcmp.c,v 1.8 2020/01/27 22:13:39 ad Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -45,6 +74,8 @@ __RCSID("$NetBSD: bcmp.c,v 1.7 2012/03/0
 #include 
 #endif
 #else
+#include 
+
 #include 
 #include 
 #endif
@@ -53,18 +84,31 @@ __RCSID("$NetBSD: bcmp.c,v 1.7 2012/03/0
  * bcmp -- vax cmpc3 instruction
  */
 int
-bcmp(const void *b1, const void *b2, size_t length)
+bcmp(const void *s1, const void *s2, size_t n)
 {
-	const char *p1 = b1, *p2 = b2;
+	const uintptr_t *b1, *b2;
+	const unsigned char *c1, *c2;
+
+	b1 = s1;
+	b2 = s2;
 
-	_DIAGASSERT(b1 != 0);
-	_DIAGASSERT(b2 != 0);
+	if uintptr_t)b1 | (uintptr_t)b2) & (sizeof(uintptr_t) - 1)) == 0) {
+		while (n >= sizeof(uintptr_t)) {
+			if (*b1++ != *b2++)
+return 1;
+			n -= sizeof(uintptr_t);
+		}
+	}
+
+	c1 = (const unsigned char *)b1;
+	c2 = (const unsigned char *)b2;
+
+	if (n != 0) {
+		do {
+			if (*c1++ != *c2++)
+return 1;
+		} while (--n != 0);
+	}
 
-	if (length == 0)
-		return(0);
-	do
-		if (*p1++ != *p2++)
-			break;
-	while (--length);
-	return length != 0;
+	return 0;
 }

Index: src/common/lib/libc/string/memcmp.c
diff -u src/common/lib/libc/string/memcmp.c:1.5 src/common/lib/libc/string/memcmp.c:1.6
--- src/common/lib/libc/string/memcmp.c:1.5	Sun Feb  4 20:22:17 2018
+++ src/common/lib/libc/string/memcmp.c	Mon Jan 27 22:13:39 2020
@@ -1,4 +1,33 @@
-/*	$NetBSD: memcmp.c,v 1.5 2018/02/04 20:22:17 mrg Exp $	*/
+/*	$NetBSD: memcmp.c,v 1.6 2020/01/27 22:13:39 ad Exp $	*/
+
+/*-
+ * Copyright (c) 2020 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Andrew Doran.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 

CVS commit: src/common/lib/libc/string

2019-03-30 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Mar 30 10:18:03 UTC 2019

Modified Files:
src/common/lib/libc/string: memset.c

Log Message:
Fix typo: __aebi_memset -> __aeabi_memset


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/common/lib/libc/string/memset.c

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

Modified files:

Index: src/common/lib/libc/string/memset.c
diff -u src/common/lib/libc/string/memset.c:1.11 src/common/lib/libc/string/memset.c:1.12
--- src/common/lib/libc/string/memset.c:1.11	Tue Feb  6 09:28:48 2018
+++ src/common/lib/libc/string/memset.c	Sat Mar 30 10:18:03 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: memset.c,v 1.11 2018/02/06 09:28:48 mrg Exp $	*/
+/*	$NetBSD: memset.c,v 1.12 2019/03/30 10:18:03 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)memset.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: memset.c,v 1.11 2018/02/06 09:28:48 mrg Exp $");
+__RCSID("$NetBSD: memset.c,v 1.12 2019/03/30 10:18:03 jmcneill Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -80,8 +80,8 @@ bzero(void *dst0, size_t length)
 void __aeabi_memset(void *, size_t, int);
 void __aeabi_memclr(void *, size_t);
 
-__strong_alias(__aeabi_memset4, __aebi_memset)
-__strong_alias(__aeabi_memset8, __aebi_memset)
+__strong_alias(__aeabi_memset4, __aeabi_memset)
+__strong_alias(__aeabi_memset8, __aeabi_memset)
 
 void
 __aeabi_memset(void *dst0, size_t length, int c)



CVS commit: src/common/lib/libc/string

2018-10-15 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Oct 15 19:32:48 UTC 2018

Modified Files:
src/common/lib/libc/string: memmem.c

Log Message:
use postincrement, like the patch
XXX: pullup-8


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

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

Modified files:

Index: src/common/lib/libc/string/memmem.c
diff -u src/common/lib/libc/string/memmem.c:1.2 src/common/lib/libc/string/memmem.c:1.3
--- src/common/lib/libc/string/memmem.c:1.2	Mon Oct 15 14:37:19 2018
+++ src/common/lib/libc/string/memmem.c	Mon Oct 15 15:32:48 2018
@@ -25,7 +25,7 @@
 #if 0
 __FBSDID("$FreeBSD: head/lib/libc/string/memmem.c 315468 2017-03-18 00:53:24Z emaste $");
 #else
-__RCSID("$NetBSD: memmem.c,v 1.2 2018/10/15 18:37:19 christos Exp $");
+__RCSID("$NetBSD: memmem.c,v 1.3 2018/10/15 19:32:48 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -40,7 +40,7 @@ static char *twobyte_memmem(const unsign
 const unsigned char *n)
 {
 	uint16_t nw = n[0] << 8 | n[1], hw = h[0] << 8 | h[1];
-	for (h += 2, k -= 2; k; k--, hw = hw << 8 | *++h)
+	for (h += 2, k -= 2; k; k--, hw = hw << 8 | *h++)
 		if (hw == nw) return __UNCONST(h - 2);
 	return hw == nw ? __UNCONST(h - 2) : 0;
 }
@@ -50,7 +50,7 @@ static char *threebyte_memmem(const unsi
 {
 	uint32_t nw = n[0] << 24 | n[1] << 16 | n[2] << 8;
 	uint32_t hw = h[0] << 24 | h[1] << 16 | h[2] << 8;
-	for (h += 3, k -= 3; k; k--, hw = (hw|*++h) << 8)
+	for (h += 3, k -= 3; k; k--, hw = (hw|*h++) << 8)
 		if (hw == nw) return __UNCONST(h - 3);
 	return hw == nw ? __UNCONST(h - 3) : 0;
 }
@@ -60,7 +60,7 @@ static char *fourbyte_memmem(const unsig
 {
 	uint32_t nw = n[0] << 24 | n[1] << 16 | n[2] << 8 | n[3];
 	uint32_t hw = h[0] << 24 | h[1] << 16 | h[2] << 8 | h[3];
-	for (h += 4, k -= 4; k; k--, hw = hw << 8 | *++h)
+	for (h += 4, k -= 4; k; k--, hw = hw << 8 | *h++)
 		if (hw == nw) return __UNCONST(h - 4);
 	return hw == nw ? __UNCONST(h - 4) : 0;
 	return 0;



CVS commit: src/common/lib/libc/string

2018-10-15 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Oct 15 18:37:19 UTC 2018

Modified Files:
src/common/lib/libc/string: memmem.c

Log Message:
Avoid out-of-bounds reads
https://www.openwall.com/lists/musl/2017/06/29/6
XXX: pullup-8


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

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

Modified files:

Index: src/common/lib/libc/string/memmem.c
diff -u src/common/lib/libc/string/memmem.c:1.1 src/common/lib/libc/string/memmem.c:1.2
--- src/common/lib/libc/string/memmem.c:1.1	Sun Jul  8 13:53:12 2018
+++ src/common/lib/libc/string/memmem.c	Mon Oct 15 14:37:19 2018
@@ -25,7 +25,7 @@
 #if 0
 __FBSDID("$FreeBSD: head/lib/libc/string/memmem.c 315468 2017-03-18 00:53:24Z emaste $");
 #else
-__RCSID("$NetBSD: memmem.c,v 1.1 2018/07/08 17:53:12 christos Exp $");
+__RCSID("$NetBSD: memmem.c,v 1.2 2018/10/15 18:37:19 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -36,29 +36,33 @@ __RCSID("$NetBSD: memmem.c,v 1.1 2018/07
 #include 
 #endif 
 
-static char *twobyte_memmem(const unsigned char *h, size_t k, const unsigned char *n)
+static char *twobyte_memmem(const unsigned char *h, size_t k,
+const unsigned char *n)
 {
-	uint16_t nw = n[0]<<8 | n[1], hw = h[0]<<8 | h[1];
-	for (h++, k--; k; k--, hw = hw<<8 | *++h)
-		if (hw == nw) return __UNCONST(h-1);
-	return 0;
+	uint16_t nw = n[0] << 8 | n[1], hw = h[0] << 8 | h[1];
+	for (h += 2, k -= 2; k; k--, hw = hw << 8 | *++h)
+		if (hw == nw) return __UNCONST(h - 2);
+	return hw == nw ? __UNCONST(h - 2) : 0;
 }
 
-static char *threebyte_memmem(const unsigned char *h, size_t k, const unsigned char *n)
+static char *threebyte_memmem(const unsigned char *h, size_t k,
+const unsigned char *n)
 {
-	uint32_t nw = n[0]<<24 | n[1]<<16 | n[2]<<8;
-	uint32_t hw = h[0]<<24 | h[1]<<16 | h[2]<<8;
-	for (h+=2, k-=2; k; k--, hw = (hw|*++h)<<8)
-		if (hw == nw) return __UNCONST(h-2);
-	return 0;
+	uint32_t nw = n[0] << 24 | n[1] << 16 | n[2] << 8;
+	uint32_t hw = h[0] << 24 | h[1] << 16 | h[2] << 8;
+	for (h += 3, k -= 3; k; k--, hw = (hw|*++h) << 8)
+		if (hw == nw) return __UNCONST(h - 3);
+	return hw == nw ? __UNCONST(h - 3) : 0;
 }
 
-static char *fourbyte_memmem(const unsigned char *h, size_t k, const unsigned char *n)
+static char *fourbyte_memmem(const unsigned char *h, size_t k,
+const unsigned char *n)
 {
-	uint32_t nw = n[0]<<24 | n[1]<<16 | n[2]<<8 | n[3];
-	uint32_t hw = h[0]<<24 | h[1]<<16 | h[2]<<8 | h[3];
-	for (h+=3, k-=3; k; k--, hw = hw<<8 | *++h)
-		if (hw == nw) return __UNCONST(h-3);
+	uint32_t nw = n[0] << 24 | n[1] << 16 | n[2] << 8 | n[3];
+	uint32_t hw = h[0] << 24 | h[1] << 16 | h[2] << 8 | h[3];
+	for (h += 4, k -= 4; k; k--, hw = hw << 8 | *++h)
+		if (hw == nw) return __UNCONST(h - 4);
+	return hw == nw ? __UNCONST(h - 4) : 0;
 	return 0;
 }
 



CVS commit: src/common/lib/libc/string

2018-08-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Aug 16 12:03:10 UTC 2018

Modified Files:
src/common/lib/libc/string: strncasecmp.c

Log Message:
toolify.


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

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

Modified files:

Index: src/common/lib/libc/string/strncasecmp.c
diff -u src/common/lib/libc/string/strncasecmp.c:1.2 src/common/lib/libc/string/strncasecmp.c:1.3
--- src/common/lib/libc/string/strncasecmp.c:1.2	Mon Jun  4 14:19:27 2007
+++ src/common/lib/libc/string/strncasecmp.c	Thu Aug 16 08:03:10 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: strncasecmp.c,v 1.2 2007/06/04 18:19:27 christos Exp $	*/
+/*	$NetBSD: strncasecmp.c,v 1.3 2018/08/16 12:03:10 christos Exp $	*/
 
 /*
  * Copyright (c) 1987, 1993
@@ -29,12 +29,16 @@
  * SUCH DAMAGE.
  */
 
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
 #if 0
 static char sccsid[] = "@(#)strcasecmp.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: strncasecmp.c,v 1.2 2007/06/04 18:19:27 christos Exp $");
+__RCSID("$NetBSD: strncasecmp.c,v 1.3 2018/08/16 12:03:10 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 



CVS commit: src/common/lib/libc/string

2018-08-11 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Aug 11 16:25:32 UTC 2018

Modified Files:
src/common/lib/libc/string: strcasecmp.c

Log Message:
Add nbotool stuff.


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

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

Modified files:

Index: src/common/lib/libc/string/strcasecmp.c
diff -u src/common/lib/libc/string/strcasecmp.c:1.2 src/common/lib/libc/string/strcasecmp.c:1.3
--- src/common/lib/libc/string/strcasecmp.c:1.2	Mon Jun  4 14:19:27 2007
+++ src/common/lib/libc/string/strcasecmp.c	Sat Aug 11 12:25:32 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: strcasecmp.c,v 1.2 2007/06/04 18:19:27 christos Exp $	*/
+/*	$NetBSD: strcasecmp.c,v 1.3 2018/08/11 16:25:32 christos Exp $	*/
 
 /*
  * Copyright (c) 1987, 1993
@@ -29,12 +29,16 @@
  * SUCH DAMAGE.
  */
 
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
 #if 0
 static char sccsid[] = "@(#)strcasecmp.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: strcasecmp.c,v 1.2 2007/06/04 18:19:27 christos Exp $");
+__RCSID("$NetBSD: strcasecmp.c,v 1.3 2018/08/11 16:25:32 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 



CVS commit: src/common/lib/libc/string

2018-07-08 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Jul  8 17:53:13 UTC 2018

Added Files:
src/common/lib/libc/string: memmem.c

Log Message:
switch to FreeBSD's memmem (faster)


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

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

Added files:

Index: src/common/lib/libc/string/memmem.c
diff -u /dev/null src/common/lib/libc/string/memmem.c:1.1
--- /dev/null	Sun Jul  8 13:53:13 2018
+++ src/common/lib/libc/string/memmem.c	Sun Jul  8 13:53:12 2018
@@ -0,0 +1,191 @@
+/*-
+ * Copyright (c) 2005-2014 Rich Felker, et al.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#include 
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+__FBSDID("$FreeBSD: head/lib/libc/string/memmem.c 315468 2017-03-18 00:53:24Z emaste $");
+#else
+__RCSID("$NetBSD: memmem.c,v 1.1 2018/07/08 17:53:12 christos Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#if !defined(_KERNEL) && !defined(_STANDALONE)
+#include 
+#include 
+#else
+#include 
+#endif 
+
+static char *twobyte_memmem(const unsigned char *h, size_t k, const unsigned char *n)
+{
+	uint16_t nw = n[0]<<8 | n[1], hw = h[0]<<8 | h[1];
+	for (h++, k--; k; k--, hw = hw<<8 | *++h)
+		if (hw == nw) return __UNCONST(h-1);
+	return 0;
+}
+
+static char *threebyte_memmem(const unsigned char *h, size_t k, const unsigned char *n)
+{
+	uint32_t nw = n[0]<<24 | n[1]<<16 | n[2]<<8;
+	uint32_t hw = h[0]<<24 | h[1]<<16 | h[2]<<8;
+	for (h+=2, k-=2; k; k--, hw = (hw|*++h)<<8)
+		if (hw == nw) return __UNCONST(h-2);
+	return 0;
+}
+
+static char *fourbyte_memmem(const unsigned char *h, size_t k, const unsigned char *n)
+{
+	uint32_t nw = n[0]<<24 | n[1]<<16 | n[2]<<8 | n[3];
+	uint32_t hw = h[0]<<24 | h[1]<<16 | h[2]<<8 | h[3];
+	for (h+=3, k-=3; k; k--, hw = hw<<8 | *++h)
+		if (hw == nw) return __UNCONST(h-3);
+	return 0;
+}
+
+#define MAX(a,b) ((a)>(b)?(a):(b))
+#define MIN(a,b) ((a)<(b)?(a):(b))
+
+#define BITOP(a,b,op) \
+ ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a
+
+/*
+ * Two Way string search algorithm, with a bad shift table applied to the last
+ * byte of the window. A bit array marks which entries in the shift table are
+ * initialized to avoid fully initializing a 1kb/2kb table.
+ *
+ * Reference: CROCHEMORE M., PERRIN D., 1991, Two-way string-matching,
+ * Journal of the ACM 38(3):651-675
+ */
+static char *twoway_memmem(const unsigned char *h, const unsigned char *z, const unsigned char *n, size_t l)
+{
+	size_t i, ip, jp, k, p, ms, p0, mem, mem0;
+	size_t byteset[32 / sizeof(size_t)] = { 0 };
+	size_t shift[256];
+
+	/* Computing length of needle and fill shift table */
+	for (i=0; i n[jp+k]) {
+			jp += k;
+			k = 1;
+			p = jp - ip;
+		} else {
+			ip = jp++;
+			k = p = 1;
+		}
+	}
+	ms = ip;
+	p0 = p;
+
+	/* And with the opposite comparison */
+	ip = (size_t)-1; jp = 0; k = p = 1;
+	while (jp+k ms+1) ms = ip;
+	else p = p0;
+
+	/* Periodic needle? */
+	if (memcmp(n, n+p, ms+1)) {
+		mem0 = 0;
+		p = MAX(ms, l-ms-1) + 1;
+	} else mem0 = l-p;
+	mem = 0;
+
+	/* Search loop */
+	for (;;) {
+		/* If remainder of haystack is shorter than needle, done */
+		if ((size_t)(z-h) < l) return 0;
+
+		/* Check last byte first; advance by shift on mismatch */
+		if (BITOP(byteset, h[l-1], &)) {
+			k = l-shift[h[l-1]];
+			if (k) {
+if (mem0 && mem && k < p) k = l-p;
+h += k;
+mem = 0;
+continue;
+			}
+		} else {
+			h += l;
+			mem = 0;
+			continue;
+		}
+
+		/* Compare right half */
+		for (k=MAX(ms+1,mem); kmem && n[k-1] == h[k-1]; k--);
+		if (k <= mem) return __UNCONST(h);
+		h += p;
+		mem = mem0;
+	}
+}
+
+void *memmem(const void *h0, size_t k, const void *n0, size_t l)
+{
+	const unsigned char *h = h0, *n = n0;
+
+	/* Return immediately on empty needle */
+	if (!l) return __UNCONST(h);
+
+	/* Return immediately 

CVS commit: src/common/lib/libc/string

2018-02-12 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Feb 12 11:14:15 UTC 2018

Modified Files:
src/common/lib/libc/string: bcopy.c

Log Message:
Complete previous by complteley removing the _DIAGASSERT from memmove -
the accidental left over from previous fired on all legitimate calls
and caused PR bin/52986 and PR lib/52987.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/common/lib/libc/string/bcopy.c

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

Modified files:

Index: src/common/lib/libc/string/bcopy.c
diff -u src/common/lib/libc/string/bcopy.c:1.12 src/common/lib/libc/string/bcopy.c:1.13
--- src/common/lib/libc/string/bcopy.c:1.12	Sun Feb  4 20:22:17 2018
+++ src/common/lib/libc/string/bcopy.c	Mon Feb 12 11:14:15 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: bcopy.c,v 1.12 2018/02/04 20:22:17 mrg Exp $	*/
+/*	$NetBSD: bcopy.c,v 1.13 2018/02/12 11:14:15 martin Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)bcopy.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: bcopy.c,v 1.12 2018/02/04 20:22:17 mrg Exp $");
+__RCSID("$NetBSD: bcopy.c,v 1.13 2018/02/12 11:14:15 martin Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -88,10 +88,6 @@ bcopy(const void *src0, void *dst0, size
 	size_t t;
 	unsigned long u;
 
-#if !defined(_KERNEL)
-	_DIAGASSERT(length == 0);
-#endif
-
 	if (length == 0 || dst == src)		/* nothing to do */
 		goto done;
 



CVS commit: src/common/lib/libc/string

2018-02-06 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Feb  6 09:28:48 UTC 2018

Modified Files:
src/common/lib/libc/string: memset.c strlen.c

Log Message:
- remove two more _DIAGASSERT() checks against not NULL for functions
  with arguments with nonnull attributes.  in two cases, leave
  code behind that should set defaults to "(null)".


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/common/lib/libc/string/memset.c
cvs rdiff -u -r1.2 -r1.3 src/common/lib/libc/string/strlen.c

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

Modified files:

Index: src/common/lib/libc/string/memset.c
diff -u src/common/lib/libc/string/memset.c:1.10 src/common/lib/libc/string/memset.c:1.11
--- src/common/lib/libc/string/memset.c:1.10	Mon Dec  2 21:21:33 2013
+++ src/common/lib/libc/string/memset.c	Tue Feb  6 09:28:48 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: memset.c,v 1.10 2013/12/02 21:21:33 joerg Exp $	*/
+/*	$NetBSD: memset.c,v 1.11 2018/02/06 09:28:48 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)memset.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: memset.c,v 1.10 2013/12/02 21:21:33 joerg Exp $");
+__RCSID("$NetBSD: memset.c,v 1.11 2018/02/06 09:28:48 mrg Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -106,8 +106,6 @@ memset(void *dst0, int c0, size_t length
 #endif
 	u_char *dst;
 
-	_DIAGASSERT(dst0 != 0);
-
 	dst = dst0;
 	/*
 	 * If not enough words, just fill bytes.  A length >= 2 words

Index: src/common/lib/libc/string/strlen.c
diff -u src/common/lib/libc/string/strlen.c:1.2 src/common/lib/libc/string/strlen.c:1.3
--- src/common/lib/libc/string/strlen.c:1.2	Mon Jun  4 18:19:27 2007
+++ src/common/lib/libc/string/strlen.c	Tue Feb  6 09:28:48 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: strlen.c,v 1.2 2007/06/04 18:19:27 christos Exp $	*/
+/*	$NetBSD: strlen.c,v 1.3 2018/02/06 09:28:48 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)strlen.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: strlen.c,v 1.2 2007/06/04 18:19:27 christos Exp $");
+__RCSID("$NetBSD: strlen.c,v 1.3 2018/02/06 09:28:48 mrg Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -50,8 +50,6 @@ strlen(const char *str)
 {
 	const char *s;
 
-	_DIAGASSERT(str != NULL);
-
 	for (s = str; *s; ++s)
 		continue;
 	return(s - str);



CVS commit: src/common/lib/libc/string

2016-10-12 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Oct 12 20:01:40 UTC 2016

Added Files:
src/common/lib/libc/string: strchrnul.c

Log Message:
Add strchrnul


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

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

Added files:

Index: src/common/lib/libc/string/strchrnul.c
diff -u /dev/null src/common/lib/libc/string/strchrnul.c:1.1
--- /dev/null	Wed Oct 12 16:01:40 2016
+++ src/common/lib/libc/string/strchrnul.c	Wed Oct 12 16:01:40 2016
@@ -0,0 +1,62 @@
+/*	$NetBSD: strchrnul.c,v 1.1 2016/10/12 20:01:40 christos Exp $	*/
+
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 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. Neither the name of the University 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 REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include 
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)index.c	8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: strchrnul.c,v 1.1 2016/10/12 20:01:40 christos Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#if !defined(_KERNEL) && !defined(_STANDALONE)
+#include "namespace.h"
+#include 
+#include 
+#else
+#include 
+#endif
+
+char *
+strchrnul(const char *p, int ch)
+{
+	const char cmp = ch;
+	_DIAGASSERT(p != NULL);
+
+	for (;; ++p) {
+		if (*p == cmp || !*p) {
+			/* LINTED const cast-away */
+			return __UNCONST(p);
+		}
+	}
+	/* NOTREACHED */
+}



CVS commit: src/common/lib/libc/string

2015-05-29 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Fri May 29 19:39:41 UTC 2015

Modified Files:
src/common/lib/libc/string: popcount32.c popcount64.c

Log Message:
Don't compile if there is a macro of the same name.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/common/lib/libc/string/popcount32.c
cvs rdiff -u -r1.7 -r1.8 src/common/lib/libc/string/popcount64.c

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

Modified files:

Index: src/common/lib/libc/string/popcount32.c
diff -u src/common/lib/libc/string/popcount32.c:1.4 src/common/lib/libc/string/popcount32.c:1.5
--- src/common/lib/libc/string/popcount32.c:1.4	Sun Aug 21 21:25:04 2011
+++ src/common/lib/libc/string/popcount32.c	Fri May 29 19:39:41 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: popcount32.c,v 1.4 2011/08/21 21:25:04 dholland Exp $	*/
+/*	$NetBSD: popcount32.c,v 1.5 2015/05/29 19:39:41 matt Exp $	*/
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -32,7 +32,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: popcount32.c,v 1.4 2011/08/21 21:25:04 dholland Exp $);
+__RCSID($NetBSD: popcount32.c,v 1.5 2015/05/29 19:39:41 matt Exp $);
 
 #if !defined(_KERNEL)  !defined(_STANDALONE)
 #include limits.h
@@ -43,6 +43,8 @@ __RCSID($NetBSD: popcount32.c,v 1.4 201
 #include machine/limits.h
 #endif
 
+#ifndef popcount32	// might be a builtin
+
 /*
  * This a hybrid algorithm for bit counting between parallel counting and
  * using multiplication.  The idea is to sum up the bits in each Byte, so
@@ -76,3 +78,5 @@ __strong_alias(popcount, popcount32)
 #if ULONG_MAX == 0xU
 __strong_alias(popcountl, popcount32)
 #endif
+
+#endif	/* !popcount32 */

Index: src/common/lib/libc/string/popcount64.c
diff -u src/common/lib/libc/string/popcount64.c:1.7 src/common/lib/libc/string/popcount64.c:1.8
--- src/common/lib/libc/string/popcount64.c:1.7	Fri Mar  9 15:41:16 2012
+++ src/common/lib/libc/string/popcount64.c	Fri May 29 19:39:41 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: popcount64.c,v 1.7 2012/03/09 15:41:16 christos Exp $	*/
+/*	$NetBSD: popcount64.c,v 1.8 2015/05/29 19:39:41 matt Exp $	*/
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -32,7 +32,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: popcount64.c,v 1.7 2012/03/09 15:41:16 christos Exp $);
+__RCSID($NetBSD: popcount64.c,v 1.8 2015/05/29 19:39:41 matt Exp $);
 
 #if !defined(_KERNEL)  !defined(_STANDALONE)
 #include limits.h
@@ -43,9 +43,11 @@ __RCSID($NetBSD: popcount64.c,v 1.7 201
 #include machine/limits.h
 #endif
 
+#ifndef popcount64	// might be defined to use a __builtin
+
 /*
  * If uint64_t is larger than size_t, the follow assumes that
- * splitting into 32bit halfes is faster.
+ * splitting into 32bit halves is faster.
  *
  * The native pocount64 version is based on the same ideas as popcount32(3),
  * see popcount32.c for comments.
@@ -83,3 +85,4 @@ __strong_alias(popcountl, popcount64)
 __strong_alias(popcountll, popcount64)
 #endif
 
+#endif /* !popcount64 */



CVS commit: src/common/lib/libc/string

2015-03-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Mar 18 20:11:35 UTC 2015

Modified Files:
src/common/lib/libc/string: consttime_memequal.c

Log Message:
Switch to the suggested constant-time result conversion.

Not hard to find CPU/compiler combinations with branches for `!res'.

While here, make everything unsigned for good measure.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/common/lib/libc/string/consttime_memequal.c

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

Modified files:

Index: src/common/lib/libc/string/consttime_memequal.c
diff -u src/common/lib/libc/string/consttime_memequal.c:1.5 src/common/lib/libc/string/consttime_memequal.c:1.6
--- src/common/lib/libc/string/consttime_memequal.c:1.5	Tue Jun 24 16:39:39 2014
+++ src/common/lib/libc/string/consttime_memequal.c	Wed Mar 18 20:11:35 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: consttime_memequal.c,v 1.5 2014/06/24 16:39:39 drochner Exp $ */
+/* $NetBSD: consttime_memequal.c,v 1.6 2015/03/18 20:11:35 riastradh Exp $ */
 
 /*
  * Written by Matthias Drochner droch...@netbsd.org.
@@ -18,20 +18,20 @@ __weak_alias(consttime_memequal,_constti
 int
 consttime_memequal(const void *b1, const void *b2, size_t len)
 {
-	const char *c1 = b1, *c2 = b2;
-	int res = 0;
+	const unsigned char *c1 = b1, *c2 = b2;
+	unsigned int res = 0;
 
-	while (len --)
+	while (len--)
 		res |= *c1++ ^ *c2++;
 
 	/*
-	 * If the compiler for your favourite architecture generates a
-	 * conditional branch for `!res', it will be a data-dependent
-	 * branch, in which case this should be replaced by
+	 * Map 0 to 1 and [1, 256) to 0 using only constant-time
+	 * arithmetic.
 	 *
-	 *	return (1 - (1  ((res - 1)  8)));
-	 *
-	 * or rewritten in assembly.
+	 * This is not simply `!res' because although many CPUs support
+	 * branchless conditional moves and many compilers will take
+	 * advantage of them, certain compilers generate branches on
+	 * certain CPUs for `!res'.
 	 */
-	return !res;
+	return (1  ((res - 1)  8));
 }



CVS commit: src/common/lib/libc/string

2014-06-24 Thread Matthias Drochner
Module Name:src
Committed By:   drochner
Date:   Tue Jun 24 16:39:39 UTC 2014

Modified Files:
src/common/lib/libc/string: consttime_memequal.c explicit_memset.c

Log Message:
add a public domain notice


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/common/lib/libc/string/consttime_memequal.c
cvs rdiff -u -r1.3 -r1.4 src/common/lib/libc/string/explicit_memset.c

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

Modified files:

Index: src/common/lib/libc/string/consttime_memequal.c
diff -u src/common/lib/libc/string/consttime_memequal.c:1.4 src/common/lib/libc/string/consttime_memequal.c:1.5
--- src/common/lib/libc/string/consttime_memequal.c:1.4	Wed Aug 28 19:31:14 2013
+++ src/common/lib/libc/string/consttime_memequal.c	Tue Jun 24 16:39:39 2014
@@ -1,4 +1,9 @@
-/* $NetBSD: consttime_memequal.c,v 1.4 2013/08/28 19:31:14 riastradh Exp $ */
+/* $NetBSD: consttime_memequal.c,v 1.5 2014/06/24 16:39:39 drochner Exp $ */
+
+/*
+ * Written by Matthias Drochner droch...@netbsd.org.
+ * Public domain.
+ */
 
 #if !defined(_KERNEL)  !defined(_STANDALONE)
 #include namespace.h

Index: src/common/lib/libc/string/explicit_memset.c
diff -u src/common/lib/libc/string/explicit_memset.c:1.3 src/common/lib/libc/string/explicit_memset.c:1.4
--- src/common/lib/libc/string/explicit_memset.c:1.3	Wed Aug 28 17:47:07 2013
+++ src/common/lib/libc/string/explicit_memset.c	Tue Jun 24 16:39:39 2014
@@ -1,4 +1,9 @@
-/* $NetBSD: explicit_memset.c,v 1.3 2013/08/28 17:47:07 riastradh Exp $ */
+/* $NetBSD: explicit_memset.c,v 1.4 2014/06/24 16:39:39 drochner Exp $ */
+
+/*
+ * Written by Matthias Drochner droch...@netbsd.org.
+ * Public domain.
+ */
 
 #if !defined(_KERNEL)  !defined(_STANDALONE)
 #include namespace.h



CVS commit: src/common/lib/libc/string

2014-01-09 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Thu Jan  9 11:25:11 UTC 2014

Modified Files:
src/common/lib/libc/string: strnlen.c

Log Message:
Make strnlen implementation usable from src/tools/compat.


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

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

Modified files:

Index: src/common/lib/libc/string/strnlen.c
diff -u src/common/lib/libc/string/strnlen.c:1.1 src/common/lib/libc/string/strnlen.c:1.2
--- src/common/lib/libc/string/strnlen.c:1.1	Thu Sep  1 22:35:18 2011
+++ src/common/lib/libc/string/strnlen.c	Thu Jan  9 11:25:11 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: strnlen.c,v 1.1 2011/09/01 22:35:18 jym Exp $	*/
+/*	$NetBSD: strnlen.c,v 1.2 2014/01/09 11:25:11 apb Exp $	*/
 
 /*-
  * Copyright (c) 2009 David Schultz d...@freebsd.org
@@ -26,9 +26,13 @@
  * SUCH DAMAGE.
  */
 
+#if HAVE_NBTOOL_CONFIG_H
+#include nbtool_config.h
+#endif
+
 #include sys/cdefs.h
 #if defined(LIBC_SCCS)  !defined(lint)
-__RCSID($NetBSD: strnlen.c,v 1.1 2011/09/01 22:35:18 jym Exp $);
+__RCSID($NetBSD: strnlen.c,v 1.2 2014/01/09 11:25:11 apb Exp $);
 #endif /* LIBC_SCCS and not lint */
 /* FreeBSD: src/lib/libc/string/strnlen.c,v 1.1 2009/02/28 06:00:58 das Exp */
 
@@ -38,6 +42,7 @@ __RCSID($NetBSD: strnlen.c,v 1.1 2011/0
 #include lib/libkern/libkern.h
 #endif
 
+#if !HAVE_STRNLEN
 size_t
 strnlen(const char *s, size_t maxlen)
 {
@@ -49,3 +54,4 @@ strnlen(const char *s, size_t maxlen)
 	}
 	return (len);
 }
+#endif /* !HAVE_STRNLEN */



CVS commit: src/common/lib/libc/string

2013-12-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Dec 27 20:24:45 UTC 2013

Added Files:
src/common/lib/libc/string: strncat.c

Log Message:
kernel needs it now too.


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

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

Added files:

Index: src/common/lib/libc/string/strncat.c
diff -u /dev/null src/common/lib/libc/string/strncat.c:1.1
--- /dev/null	Fri Dec 27 15:24:45 2013
+++ src/common/lib/libc/string/strncat.c	Fri Dec 27 15:24:45 2013
@@ -0,0 +1,76 @@
+/*	$NetBSD: strncat.c,v 1.1 2013/12/27 20:24:45 christos Exp $	*/
+
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 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. Neither the name of the University 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 REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include sys/cdefs.h
+#if defined(LIBC_SCCS)  !defined(lint)
+#if 0
+static char sccsid[] = @(#)strncat.c	8.1 (Berkeley) 6/4/93;
+#else
+__RCSID($NetBSD: strncat.c,v 1.1 2013/12/27 20:24:45 christos Exp $);
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include assert.h
+#include string.h
+
+#ifdef _FORTIFY_SOURCE
+#undef strncat
+#endif
+
+/*
+ * Concatenate src on the end of dst.  At most strlen(dst)+n+1 bytes
+ * are written at dst (at most n+1 bytes being appended).  Return dst.
+ */
+char *
+strncat(char *dst, const char *src, size_t n)
+{
+
+	_DIAGASSERT(dst != NULL);
+	_DIAGASSERT(src != NULL);
+
+	if (n != 0) {
+		char *d = dst;
+		const char *s = src;
+
+		while (*d != 0)
+			d++;
+		do {
+			if ((*d = *s++) == 0)
+break;
+			d++;
+		} while (--n != 0);
+		*d = 0;
+	}
+	return (dst);
+}



CVS commit: src/common/lib/libc/string

2013-12-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Dec 27 20:26:53 UTC 2013

Modified Files:
src/common/lib/libc/string: strncat.c

Log Message:
make it kernel friendly.


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

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

Modified files:

Index: src/common/lib/libc/string/strncat.c
diff -u src/common/lib/libc/string/strncat.c:1.1 src/common/lib/libc/string/strncat.c:1.2
--- src/common/lib/libc/string/strncat.c:1.1	Fri Dec 27 15:24:45 2013
+++ src/common/lib/libc/string/strncat.c	Fri Dec 27 15:26:53 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: strncat.c,v 1.1 2013/12/27 20:24:45 christos Exp $	*/
+/*	$NetBSD: strncat.c,v 1.2 2013/12/27 20:26:53 christos Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -37,12 +37,16 @@
 #if 0
 static char sccsid[] = @(#)strncat.c	8.1 (Berkeley) 6/4/93;
 #else
-__RCSID($NetBSD: strncat.c,v 1.1 2013/12/27 20:24:45 christos Exp $);
+__RCSID($NetBSD: strncat.c,v 1.2 2013/12/27 20:26:53 christos Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
+#if !defined(_KERNEL)  !defined(_STANDALONE)
 #include assert.h
 #include string.h
+#else
+#include lib/libkern/libkern.h
+#endif
 
 #ifdef _FORTIFY_SOURCE
 #undef strncat



CVS commit: src/common/lib/libc/string

2013-08-28 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Aug 28 19:31:14 UTC 2013

Modified Files:
src/common/lib/libc/string: consttime_memequal.c

Log Message:
Comment on possible data-dependent branch in `!res'.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/common/lib/libc/string/consttime_memequal.c

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

Modified files:

Index: src/common/lib/libc/string/consttime_memequal.c
diff -u src/common/lib/libc/string/consttime_memequal.c:1.3 src/common/lib/libc/string/consttime_memequal.c:1.4
--- src/common/lib/libc/string/consttime_memequal.c:1.3	Wed Aug 28 17:47:07 2013
+++ src/common/lib/libc/string/consttime_memequal.c	Wed Aug 28 19:31:14 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: consttime_memequal.c,v 1.3 2013/08/28 17:47:07 riastradh Exp $ */
+/* $NetBSD: consttime_memequal.c,v 1.4 2013/08/28 19:31:14 riastradh Exp $ */
 
 #if !defined(_KERNEL)  !defined(_STANDALONE)
 #include namespace.h
@@ -18,5 +18,15 @@ consttime_memequal(const void *b1, const
 
 	while (len --)
 		res |= *c1++ ^ *c2++;
+
+	/*
+	 * If the compiler for your favourite architecture generates a
+	 * conditional branch for `!res', it will be a data-dependent
+	 * branch, in which case this should be replaced by
+	 *
+	 *	return (1 - (1  ((res - 1)  8)));
+	 *
+	 * or rewritten in assembly.
+	 */
 	return !res;
 }



CVS commit: src/common/lib/libc/string

2013-07-01 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Mon Jul  1 20:51:59 UTC 2013

Modified Files:
src/common/lib/libc/string: strcmp.c

Log Message:
Don't pick up strcmp as macro from libkern.h.


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

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

Modified files:

Index: src/common/lib/libc/string/strcmp.c
diff -u src/common/lib/libc/string/strcmp.c:1.2 src/common/lib/libc/string/strcmp.c:1.3
--- src/common/lib/libc/string/strcmp.c:1.2	Mon Jun  4 18:19:27 2007
+++ src/common/lib/libc/string/strcmp.c	Mon Jul  1 20:51:59 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: strcmp.c,v 1.2 2007/06/04 18:19:27 christos Exp $	*/
+/*	$NetBSD: strcmp.c,v 1.3 2013/07/01 20:51:59 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = @(#)strcmp.c	8.1 (Berkeley) 6/4/93;
 #else
-__RCSID($NetBSD: strcmp.c,v 1.2 2007/06/04 18:19:27 christos Exp $);
+__RCSID($NetBSD: strcmp.c,v 1.3 2013/07/01 20:51:59 joerg Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -48,6 +48,8 @@ __RCSID($NetBSD: strcmp.c,v 1.2 2007/06
 #include lib/libkern/libkern.h
 #endif
 
+#undef strcmp
+
 /*
  * Compare strings.
  */



CVS commit: src/common/lib/libc/string

2013-01-22 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Wed Jan 23 07:57:27 UTC 2013

Modified Files:
src/common/lib/libc/string: strlcat.c

Log Message:
Add a (unused) variant of strlcat that uses strnlen and strlcpy to do the work.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/common/lib/libc/string/strlcat.c

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

Modified files:

Index: src/common/lib/libc/string/strlcat.c
diff -u src/common/lib/libc/string/strlcat.c:1.3 src/common/lib/libc/string/strlcat.c:1.4
--- src/common/lib/libc/string/strlcat.c:1.3	Mon Jun  4 18:19:27 2007
+++ src/common/lib/libc/string/strlcat.c	Wed Jan 23 07:57:27 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: strlcat.c,v 1.3 2007/06/04 18:19:27 christos Exp $	*/
+/*	$NetBSD: strlcat.c,v 1.4 2013/01/23 07:57:27 matt Exp $	*/
 /*	$OpenBSD: strlcat.c,v 1.10 2003/04/12 21:56:39 millert Exp $	*/
 
 /*
@@ -24,7 +24,7 @@
 
 #include sys/cdefs.h
 #if defined(LIBC_SCCS)  !defined(lint)
-__RCSID($NetBSD: strlcat.c,v 1.3 2007/06/04 18:19:27 christos Exp $);
+__RCSID($NetBSD: strlcat.c,v 1.4 2013/01/23 07:57:27 matt Exp $);
 #endif /* LIBC_SCCS and not lint */
 
 #ifdef _LIBC
@@ -55,6 +55,7 @@ __weak_alias(strlcat, _strlcat)
 size_t
 strlcat(char *dst, const char *src, size_t siz)
 {
+#if 1
 	char *d = dst;
 	const char *s = src;
 	size_t n = siz;
@@ -81,5 +82,20 @@ strlcat(char *dst, const char *src, size
 	*d = '\0';
 
 	return(dlen + (s - src));	/* count does not include NUL */
+#else
+	_DIAGASSERT(dst != NULL);
+	_DIAGASSERT(src != NULL);
+
+	/*
+	 * Find length of string in dst (maxing out at siz).
+	 */
+	size_t dlen = strnlen(dst, siz);
+
+	/*
+	 * Copy src into any remaining space in dst (truncating if needed).
+	 * Note strlcpy(dst, src, 0) returns strlen(src).
+	 */
+	return dlen + strlcpy(dst + dlen, src, siz - dlen);
+#endif
 }
 #endif



CVS commit: src/common/lib/libc/string

2012-03-02 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Fri Mar  2 16:19:15 UTC 2012

Modified Files:
src/common/lib/libc/string: memset2.c

Log Message:
Change CTASSERT to __CTASSERT (the spelling used in sys/cdefs.h),
include sys/cdefs.h so that it will be defined,
and move it to a better place.

The previous CTASSERT would never have been used because
of the ifdef.  If it had been used, it would have had
unwanted effects from being just after the static inline
that appears when BZERO is defined.

Also move the __RCSID to a more conventional location.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/common/lib/libc/string/memset2.c

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

Modified files:

Index: src/common/lib/libc/string/memset2.c
diff -u src/common/lib/libc/string/memset2.c:1.3 src/common/lib/libc/string/memset2.c:1.4
--- src/common/lib/libc/string/memset2.c:1.3	Tue Nov  8 16:52:11 2011
+++ src/common/lib/libc/string/memset2.c	Fri Mar  2 16:19:15 2012
@@ -27,6 +27,11 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include sys/cdefs.h
+#if defined(LIBC_SCCS)  !defined(lint)
+__RCSID($NetBSD: memset2.c,v 1.4 2012/03/02 16:19:15 apb Exp $);
+#endif /* LIBC_SCCS and not lint */
+
 #include sys/types.h
 
 #if !defined(_KERNEL)  !defined(_STANDALONE)
@@ -52,15 +57,13 @@
 #endif
 #undef memset
 
-#if defined(LIBC_SCCS)  !defined(lint)
-__RCSID($NetBSD: memset2.c,v 1.3 2011/11/08 16:52:11 joerg Exp $);
-#endif /* LIBC_SCCS and not lint */
-
 /*
  * Assume uregister_t is the widest non-synthetic unsigned type.
  */
 typedef uregister_t memword_t;
 
+__CTASSERT((~(memword_t)0U  1) != ~(memword_t)0U);
+
 #ifdef BZERO
 static inline
 #define	memset memset0
@@ -71,10 +74,6 @@ static
 #define memset test_memset
 #endif
 
-#ifdef CTASSERT
-CTASSERT((~(memword_t)0U  1) != ~(memword_t)0U);
-#endif
-
 void *
 memset(void *addr, int c, size_t len)
 {



CVS commit: src/common/lib/libc/string

2012-03-02 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Fri Mar  2 16:22:27 UTC 2012

Modified Files:
src/common/lib/libc/string: memset2.c

Log Message:
remove trailing white space


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/common/lib/libc/string/memset2.c

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

Modified files:

Index: src/common/lib/libc/string/memset2.c
diff -u src/common/lib/libc/string/memset2.c:1.4 src/common/lib/libc/string/memset2.c:1.5
--- src/common/lib/libc/string/memset2.c:1.4	Fri Mar  2 16:19:15 2012
+++ src/common/lib/libc/string/memset2.c	Fri Mar  2 16:22:27 2012
@@ -29,7 +29,7 @@
 
 #include sys/cdefs.h
 #if defined(LIBC_SCCS)  !defined(lint)
-__RCSID($NetBSD: memset2.c,v 1.4 2012/03/02 16:19:15 apb Exp $);
+__RCSID($NetBSD: memset2.c,v 1.5 2012/03/02 16:22:27 apb Exp $);
 #endif /* LIBC_SCCS and not lint */
 
 #include sys/types.h



CVS commit: src/common/lib/libc/string

2011-11-08 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Tue Nov  8 16:52:11 UTC 2011

Modified Files:
src/common/lib/libc/string: memcmp.c memset.c memset2.c strcpy.c

Log Message:
libkern.h maps memcmp, memset and strcpy to the compiler builtins on
some platforms, so make sure to #undef them first.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/common/lib/libc/string/memcmp.c \
src/common/lib/libc/string/memset2.c src/common/lib/libc/string/strcpy.c
cvs rdiff -u -r1.8 -r1.9 src/common/lib/libc/string/memset.c

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

Modified files:

Index: src/common/lib/libc/string/memcmp.c
diff -u src/common/lib/libc/string/memcmp.c:1.2 src/common/lib/libc/string/memcmp.c:1.3
--- src/common/lib/libc/string/memcmp.c:1.2	Mon Jun  4 18:19:27 2007
+++ src/common/lib/libc/string/memcmp.c	Tue Nov  8 16:52:11 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: memcmp.c,v 1.2 2007/06/04 18:19:27 christos Exp $	*/
+/*	$NetBSD: memcmp.c,v 1.3 2011/11/08 16:52:11 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = @(#)memcmp.c	8.1 (Berkeley) 6/4/93;
 #else
-__RCSID($NetBSD: memcmp.c,v 1.2 2007/06/04 18:19:27 christos Exp $);
+__RCSID($NetBSD: memcmp.c,v 1.3 2011/11/08 16:52:11 joerg Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -48,6 +48,7 @@ __RCSID($NetBSD: memcmp.c,v 1.2 2007/06
 #include lib/libkern/libkern.h
 #endif 
 
+#undef memcmp
 /*
  * Compare memory regions.
  */
Index: src/common/lib/libc/string/memset2.c
diff -u src/common/lib/libc/string/memset2.c:1.2 src/common/lib/libc/string/memset2.c:1.3
--- src/common/lib/libc/string/memset2.c:1.2	Mon Dec 14 00:39:01 2009
+++ src/common/lib/libc/string/memset2.c	Tue Nov  8 16:52:11 2011
@@ -49,11 +49,11 @@
 
 #ifdef _FORTIFY_SOURCE
 #undef bzero
-#undef memset
 #endif
+#undef memset
 
 #if defined(LIBC_SCCS)  !defined(lint)
-__RCSID($NetBSD: memset2.c,v 1.2 2009/12/14 00:39:01 matt Exp $);
+__RCSID($NetBSD: memset2.c,v 1.3 2011/11/08 16:52:11 joerg Exp $);
 #endif /* LIBC_SCCS and not lint */
 
 /*
Index: src/common/lib/libc/string/strcpy.c
diff -u src/common/lib/libc/string/strcpy.c:1.2 src/common/lib/libc/string/strcpy.c:1.3
--- src/common/lib/libc/string/strcpy.c:1.2	Mon Jun  4 18:19:27 2007
+++ src/common/lib/libc/string/strcpy.c	Tue Nov  8 16:52:11 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: strcpy.c,v 1.2 2007/06/04 18:19:27 christos Exp $	*/
+/*	$NetBSD: strcpy.c,v 1.3 2011/11/08 16:52:11 joerg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = @(#)strcpy.c	8.1 (Berkeley) 6/4/93;
 #else
-__RCSID($NetBSD: strcpy.c,v 1.2 2007/06/04 18:19:27 christos Exp $);
+__RCSID($NetBSD: strcpy.c,v 1.3 2011/11/08 16:52:11 joerg Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -45,9 +45,7 @@ __RCSID($NetBSD: strcpy.c,v 1.2 2007/06
 #include lib/libkern/libkern.h
 #endif
 
-#ifdef _FORTIFY_SOURCE
 #undef strcpy
-#endif
 
 char *
 strcpy(char *to, const char *from)

Index: src/common/lib/libc/string/memset.c
diff -u src/common/lib/libc/string/memset.c:1.8 src/common/lib/libc/string/memset.c:1.9
--- src/common/lib/libc/string/memset.c:1.8	Wed Mar 18 12:25:06 2009
+++ src/common/lib/libc/string/memset.c	Tue Nov  8 16:52:11 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: memset.c,v 1.8 2009/03/18 12:25:06 tsutsui Exp $	*/
+/*	$NetBSD: memset.c,v 1.9 2011/11/08 16:52:11 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = @(#)memset.c	8.1 (Berkeley) 6/4/93;
 #else
-__RCSID($NetBSD: memset.c,v 1.8 2009/03/18 12:25:06 tsutsui Exp $);
+__RCSID($NetBSD: memset.c,v 1.9 2011/11/08 16:52:11 joerg Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -60,8 +60,8 @@ __RCSID($NetBSD: memset.c,v 1.8 2009/03
 
 #ifdef _FORTIFY_SOURCE
 #undef bzero
-#undef memset
 #endif
+#undef memset
 
 #ifndef __OPTIMIZE_SIZE__
 #ifdef BZERO



CVS commit: src/common/lib/libc/string

2011-08-31 Thread Iain Hibbert
Module Name:src
Committed By:   plunky
Date:   Wed Aug 31 15:48:32 UTC 2011

Modified Files:
src/common/lib/libc/string: strchr.c

Log Message:
NULL does not need a cast


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/common/lib/libc/string/strchr.c

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

Modified files:

Index: src/common/lib/libc/string/strchr.c
diff -u src/common/lib/libc/string/strchr.c:1.4 src/common/lib/libc/string/strchr.c:1.5
--- src/common/lib/libc/string/strchr.c:1.4	Fri Jul 17 19:37:57 2009
+++ src/common/lib/libc/string/strchr.c	Wed Aug 31 15:48:32 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: strchr.c,v 1.4 2009/07/17 19:37:57 dsl Exp $	*/
+/*	$NetBSD: strchr.c,v 1.5 2011/08/31 15:48:32 plunky 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.4 2009/07/17 19:37:57 dsl Exp $);
+__RCSID($NetBSD: strchr.c,v 1.5 2011/08/31 15:48:32 plunky Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -59,7 +59,7 @@
 			return(__UNCONST(p));
 		}
 		if (!*p)
-			return((char *)NULL);
+			return(NULL);
 	}
 	/* NOTREACHED */
 }



CVS commit: src/common/lib/libc/string

2011-08-21 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sun Aug 21 21:25:04 UTC 2011

Modified Files:
src/common/lib/libc/string: popcount32.c popcount64.c

Log Message:
Requires stdint.h.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/common/lib/libc/string/popcount32.c
cvs rdiff -u -r1.5 -r1.6 src/common/lib/libc/string/popcount64.c

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

Modified files:

Index: src/common/lib/libc/string/popcount32.c
diff -u src/common/lib/libc/string/popcount32.c:1.3 src/common/lib/libc/string/popcount32.c:1.4
--- src/common/lib/libc/string/popcount32.c:1.3	Tue Jul 21 19:56:55 2009
+++ src/common/lib/libc/string/popcount32.c	Sun Aug 21 21:25:04 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: popcount32.c,v 1.3 2009/07/21 19:56:55 drochner Exp $	*/
+/*	$NetBSD: popcount32.c,v 1.4 2011/08/21 21:25:04 dholland Exp $	*/
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -32,10 +32,11 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: popcount32.c,v 1.3 2009/07/21 19:56:55 drochner Exp $);
+__RCSID($NetBSD: popcount32.c,v 1.4 2011/08/21 21:25:04 dholland Exp $);
 
 #if !defined(_KERNEL)  !defined(_STANDALONE)
 #include limits.h
+#include stdint.h
 #include strings.h
 #else
 #include lib/libkern/libkern.h

Index: src/common/lib/libc/string/popcount64.c
diff -u src/common/lib/libc/string/popcount64.c:1.5 src/common/lib/libc/string/popcount64.c:1.6
--- src/common/lib/libc/string/popcount64.c:1.5	Wed Aug  5 15:04:15 2009
+++ src/common/lib/libc/string/popcount64.c	Sun Aug 21 21:25:04 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: popcount64.c,v 1.5 2009/08/05 15:04:15 joerg Exp $	*/
+/*	$NetBSD: popcount64.c,v 1.6 2011/08/21 21:25:04 dholland Exp $	*/
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -32,10 +32,11 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: popcount64.c,v 1.5 2009/08/05 15:04:15 joerg Exp $);
+__RCSID($NetBSD: popcount64.c,v 1.6 2011/08/21 21:25:04 dholland Exp $);
 
 #if !defined(_KERNEL)  !defined(_STANDALONE)
 #include limits.h
+#include stdint.h
 #include strings.h
 #else
 #include lib/libkern/libkern.h



CVS commit: src/common/lib/libc/string

2011-08-06 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Aug  7 01:52:48 UTC 2011

Modified Files:
src/common/lib/libc/string: ffs.c

Log Message:
add a weak alias to __ffssi2, needed for hppa gcc 4.5.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/common/lib/libc/string/ffs.c

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

Modified files:

Index: src/common/lib/libc/string/ffs.c
diff -u src/common/lib/libc/string/ffs.c:1.3 src/common/lib/libc/string/ffs.c:1.4
--- src/common/lib/libc/string/ffs.c:1.3	Fri Nov  2 21:05:06 2007
+++ src/common/lib/libc/string/ffs.c	Sun Aug  7 01:52:47 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs.c,v 1.3 2007/11/02 21:05:06 christos Exp $	*/
+/*	$NetBSD: ffs.c,v 1.4 2011/08/07 01:52:47 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = @(#)ffs.c	8.1 (Berkeley) 6/4/93;
 #else
-__RCSID($NetBSD: ffs.c,v 1.3 2007/11/02 21:05:06 christos Exp $);
+__RCSID($NetBSD: ffs.c,v 1.4 2011/08/07 01:52:47 mrg Exp $);
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -53,6 +53,7 @@
 /*
  * ffs -- vax ffs instruction
  */
+__weak_alias(__ffssi2,ffs)
 int
 ffs(int mask)
 {



CVS commit: src/common/lib/libc/string

2009-08-05 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Wed Aug  5 15:04:15 UTC 2009

Modified Files:
src/common/lib/libc/string: popcount64.c

Log Message:
Fix a comment to not be self-referencing.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/common/lib/libc/string/popcount64.c

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

Modified files:

Index: src/common/lib/libc/string/popcount64.c
diff -u src/common/lib/libc/string/popcount64.c:1.4 src/common/lib/libc/string/popcount64.c:1.5
--- src/common/lib/libc/string/popcount64.c:1.4	Tue Jul 21 19:56:55 2009
+++ src/common/lib/libc/string/popcount64.c	Wed Aug  5 15:04:15 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: popcount64.c,v 1.4 2009/07/21 19:56:55 drochner Exp $	*/
+/*	$NetBSD: popcount64.c,v 1.5 2009/08/05 15:04:15 joerg Exp $	*/
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -32,7 +32,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: popcount64.c,v 1.4 2009/07/21 19:56:55 drochner Exp $);
+__RCSID($NetBSD: popcount64.c,v 1.5 2009/08/05 15:04:15 joerg Exp $);
 
 #if !defined(_KERNEL)  !defined(_STANDALONE)
 #include limits.h
@@ -46,8 +46,8 @@
  * If uint64_t is larger than size_t, the follow assumes that
  * splitting into 32bit halfes is faster.
  *
- * The native pocount64 version is based on the same ideas as popcount64(3),
- * see popcount64.c for comments.
+ * The native pocount64 version is based on the same ideas as popcount32(3),
+ * see popcount32.c for comments.
  */
 
 #if SIZE_MAX  0xULL



CVS commit: src/common/lib/libc/string

2009-07-21 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Tue Jul 21 17:14:12 UTC 2009

Modified Files:
src/common/lib/libc/string: popcount64.c

Log Message:
Make the constant u_longlong too, lint is just too stupid...


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

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

Modified files:

Index: src/common/lib/libc/string/popcount64.c
diff -u src/common/lib/libc/string/popcount64.c:1.2 src/common/lib/libc/string/popcount64.c:1.3
--- src/common/lib/libc/string/popcount64.c:1.2	Tue Jul 21 16:10:48 2009
+++ src/common/lib/libc/string/popcount64.c	Tue Jul 21 17:14:12 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: popcount64.c,v 1.2 2009/07/21 16:10:48 joerg Exp $	*/
+/*	$NetBSD: popcount64.c,v 1.3 2009/07/21 17:14:12 joerg Exp $	*/
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -32,7 +32,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: popcount64.c,v 1.2 2009/07/21 16:10:48 joerg Exp $);
+__RCSID($NetBSD: popcount64.c,v 1.3 2009/07/21 17:14:12 joerg Exp $);
 
 #if !defined(_KERNEL)  !defined(_STANDALONE)
 #include limits.h
@@ -55,7 +55,7 @@
 popcount64(uint64_t v)
 {
 	return popcount32((uint32_t)(v  32)) +
-	popcount32((uint32_t)(v  0xU));
+	popcount32((uint32_t)(v  0xULL));
 }
 #else
 unsigned int