CVS commit: src/lib/libc/stdlib

2021-02-26 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Feb 26 19:25:12 UTC 2021

Modified Files:
src/lib/libc/stdlib: reallocarray.c

Log Message:
arrange for tools build


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/lib/libc/stdlib/reallocarray.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/stdlib/reallocarray.c
diff -u src/lib/libc/stdlib/reallocarray.c:1.10 src/lib/libc/stdlib/reallocarray.c:1.11
--- src/lib/libc/stdlib/reallocarray.c:1.10	Thu Jan  4 15:57:29 2018
+++ src/lib/libc/stdlib/reallocarray.c	Fri Feb 26 14:25:12 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: reallocarray.c,v 1.10 2018/01/04 20:57:29 kamil Exp $	*/
+/*	$NetBSD: reallocarray.c,v 1.11 2021/02/26 19:25:12 christos Exp $	*/
 /*	$OpenBSD: reallocarray.c,v 1.1 2014/05/08 21:43:49 deraadt Exp $	*/
 
 /*-
@@ -30,8 +30,12 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#ifdef HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif /* HAVE_NBTOOL_CONFIG_H */
+
 #include 
-__RCSID("$NetBSD: reallocarray.c,v 1.10 2018/01/04 20:57:29 kamil Exp $");
+__RCSID("$NetBSD: reallocarray.c,v 1.11 2021/02/26 19:25:12 christos Exp $");
 
 #include "namespace.h"
 



CVS commit: src/lib/libc/stdlib

2020-05-03 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun May  3 07:32:54 UTC 2020

Modified Files:
src/lib/libc/stdlib: jemalloc.c

Log Message:
turn off TLS for mips on old jemalloc.  it doesn't work.


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/lib/libc/stdlib/jemalloc.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/stdlib/jemalloc.c
diff -u src/lib/libc/stdlib/jemalloc.c:1.51 src/lib/libc/stdlib/jemalloc.c:1.52
--- src/lib/libc/stdlib/jemalloc.c:1.51	Wed Apr 22 08:48:12 2020
+++ src/lib/libc/stdlib/jemalloc.c	Sun May  3 07:32:54 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: jemalloc.c,v 1.51 2020/04/22 08:48:12 rin Exp $	*/
+/*	$NetBSD: jemalloc.c,v 1.52 2020/05/03 07:32:54 mrg Exp $	*/
 
 /*-
  * Copyright (C) 2006,2007 Jason Evans .
@@ -117,7 +117,7 @@
 
 #include 
 /* __FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.147 2007/06/15 22:00:16 jasone Exp $"); */ 
-__RCSID("$NetBSD: jemalloc.c,v 1.51 2020/04/22 08:48:12 rin Exp $");
+__RCSID("$NetBSD: jemalloc.c,v 1.52 2020/05/03 07:32:54 mrg Exp $");
 
 #ifdef __FreeBSD__
 #include "libc_private.h"
@@ -284,6 +284,9 @@ __RCSID("$NetBSD: jemalloc.c,v 1.51 2020
 #  endif
 #  define QUANTUM_2POW_MIN	4
 #  define USE_BRK
+#  if defined(__mips__)
+#define NO_TLS
+#  endif
 #endif
 #ifdef __hppa__ 
 #  define QUANTUM_2POW_MIN	4



CVS commit: src/lib/libc/stdlib

2020-04-22 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Apr 22 08:48:12 UTC 2020

Modified Files:
src/lib/libc/stdlib: jemalloc.c

Log Message:
Use __mc68010__ to distinguish m68000 (sun2) from other m68k ports;
__mc68000__ is defined both for m68000 and m68k.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/lib/libc/stdlib/jemalloc.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/stdlib/jemalloc.c
diff -u src/lib/libc/stdlib/jemalloc.c:1.50 src/lib/libc/stdlib/jemalloc.c:1.51
--- src/lib/libc/stdlib/jemalloc.c:1.50	Wed Apr 22 08:45:06 2020
+++ src/lib/libc/stdlib/jemalloc.c	Wed Apr 22 08:48:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: jemalloc.c,v 1.50 2020/04/22 08:45:06 rin Exp $	*/
+/*	$NetBSD: jemalloc.c,v 1.51 2020/04/22 08:48:12 rin Exp $	*/
 
 /*-
  * Copyright (C) 2006,2007 Jason Evans .
@@ -117,7 +117,7 @@
 
 #include 
 /* __FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.147 2007/06/15 22:00:16 jasone Exp $"); */ 
-__RCSID("$NetBSD: jemalloc.c,v 1.50 2020/04/22 08:45:06 rin Exp $");
+__RCSID("$NetBSD: jemalloc.c,v 1.51 2020/04/22 08:48:12 rin Exp $");
 
 #ifdef __FreeBSD__
 #include "libc_private.h"
@@ -271,8 +271,8 @@ __RCSID("$NetBSD: jemalloc.c,v 1.50 2020
 #  define QUANTUM_2POW_MIN	4
 #  define SIZEOF_PTR_2POW	2
 #  define USE_BRK
-#  ifdef __mc68000__
-#  define NO_TLS
+#  ifdef __mc68010__
+#define NO_TLS
 #  endif
 #endif
 #if defined(__mips__) || defined(__riscv__)



CVS commit: src/lib/libc/stdlib

2020-04-22 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Apr 22 08:45:06 UTC 2020

Modified Files:
src/lib/libc/stdlib: jemalloc.c

Log Message:
Fix previous for libhack, where _REENTRANT is not defined;
arenas_map_key is used only when NO_TLS && _REENTRANT.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/lib/libc/stdlib/jemalloc.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/stdlib/jemalloc.c
diff -u src/lib/libc/stdlib/jemalloc.c:1.49 src/lib/libc/stdlib/jemalloc.c:1.50
--- src/lib/libc/stdlib/jemalloc.c:1.49	Tue Apr 21 22:22:55 2020
+++ src/lib/libc/stdlib/jemalloc.c	Wed Apr 22 08:45:06 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: jemalloc.c,v 1.49 2020/04/21 22:22:55 joerg Exp $	*/
+/*	$NetBSD: jemalloc.c,v 1.50 2020/04/22 08:45:06 rin Exp $	*/
 
 /*-
  * Copyright (C) 2006,2007 Jason Evans .
@@ -117,7 +117,7 @@
 
 #include 
 /* __FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.147 2007/06/15 22:00:16 jasone Exp $"); */ 
-__RCSID("$NetBSD: jemalloc.c,v 1.49 2020/04/21 22:22:55 joerg Exp $");
+__RCSID("$NetBSD: jemalloc.c,v 1.50 2020/04/22 08:45:06 rin Exp $");
 
 #ifdef __FreeBSD__
 #include "libc_private.h"
@@ -775,14 +775,14 @@ static __attribute__((tls_model("initial
 __thread arena_t	**arenas_map;
 #else
 static arena_t	**arenas_map;
-static thread_key_t arenas_map_key = -1;
 #endif
 
 #if !defined(NO_TLS) || !defined(_REENTRANT)
 # define	get_arenas_map()	(arenas_map)
 # define	set_arenas_map(x)	(arenas_map = x)
-#else
+#else /* NO_TLS && _REENTRANT */
 
+static thread_key_t arenas_map_key = -1;
 
 static inline arena_t **
 get_arenas_map(void)
@@ -823,7 +823,7 @@ set_arenas_map(arena_t **a)
 	thr_setspecific(arenas_map_key, a);
 #endif
 }
-#endif
+#endif /* NO_TLS && _REENTRANT */
 
 #ifdef MALLOC_STATS
 /* Chunk statistics. */



CVS commit: src/lib/libc/stdlib

2020-04-21 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Tue Apr 21 22:22:55 UTC 2020

Modified Files:
src/lib/libc/stdlib: jemalloc.c

Log Message:
Switch to using TLS in old jemalloc for everywhere but VAX and sun2.


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/lib/libc/stdlib/jemalloc.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/stdlib/jemalloc.c
diff -u src/lib/libc/stdlib/jemalloc.c:1.48 src/lib/libc/stdlib/jemalloc.c:1.49
--- src/lib/libc/stdlib/jemalloc.c:1.48	Mon Jan 13 19:14:37 2020
+++ src/lib/libc/stdlib/jemalloc.c	Tue Apr 21 22:22:55 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: jemalloc.c,v 1.48 2020/01/13 19:14:37 joerg Exp $	*/
+/*	$NetBSD: jemalloc.c,v 1.49 2020/04/21 22:22:55 joerg Exp $	*/
 
 /*-
  * Copyright (C) 2006,2007 Jason Evans .
@@ -100,7 +100,6 @@
 #ifdef __NetBSD__
 #  define xutrace(a, b)		utrace("malloc", (a), (b))
 #  define __DECONST(x, y)	((x)__UNCONST(y))
-#  define NO_TLS
 #else
 #  define xutrace(a, b)		utrace((a), (b))
 #endif	/* __NetBSD__ */
@@ -118,7 +117,7 @@
 
 #include 
 /* __FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.147 2007/06/15 22:00:16 jasone Exp $"); */ 
-__RCSID("$NetBSD: jemalloc.c,v 1.48 2020/01/13 19:14:37 joerg Exp $");
+__RCSID("$NetBSD: jemalloc.c,v 1.49 2020/04/21 22:22:55 joerg Exp $");
 
 #ifdef __FreeBSD__
 #include "libc_private.h"
@@ -222,13 +221,11 @@ __RCSID("$NetBSD: jemalloc.c,v 1.48 2020
 #  define QUANTUM_2POW_MIN	4
 #  define SIZEOF_PTR_2POW	3
 #  define TINY_MIN_2POW		3
-#  define NO_TLS
 #endif
 #ifdef __sparc64__
 #  define QUANTUM_2POW_MIN	4
 #  define SIZEOF_PTR_2POW	3
 #  define TINY_MIN_2POW		3
-#  define NO_TLS
 #endif
 #ifdef __amd64__
 #  define QUANTUM_2POW_MIN	4
@@ -242,7 +239,6 @@ __RCSID("$NetBSD: jemalloc.c,v 1.48 2020
 #  ifdef __ARM_EABI__
 #define TINY_MIN_2POW	3
 #  endif
-#  define NO_TLS
 #endif
 #ifdef __powerpc__
 #  define QUANTUM_2POW_MIN	4
@@ -264,6 +260,7 @@ __RCSID("$NetBSD: jemalloc.c,v 1.48 2020
 #  define QUANTUM_2POW_MIN	4
 #  define SIZEOF_PTR_2POW	2
 #  define USE_BRK
+#  define NO_TLS
 #endif
 #ifdef __sh__
 #  define QUANTUM_2POW_MIN	4
@@ -274,6 +271,9 @@ __RCSID("$NetBSD: jemalloc.c,v 1.48 2020
 #  define QUANTUM_2POW_MIN	4
 #  define SIZEOF_PTR_2POW	2
 #  define USE_BRK
+#  ifdef __mc68000__
+#  define NO_TLS
+#  endif
 #endif
 #if defined(__mips__) || defined(__riscv__)
 #  ifdef _LP64
@@ -771,9 +771,11 @@ static malloc_mutex_t	arenas_mtx; /* Pro
  * for allocations.
  */
 #ifndef NO_TLS
-static __thread arena_t	**arenas_map;
+static __attribute__((tls_model("initial-exec")))
+__thread arena_t	**arenas_map;
 #else
 static arena_t	**arenas_map;
+static thread_key_t arenas_map_key = -1;
 #endif
 
 #if !defined(NO_TLS) || !defined(_REENTRANT)
@@ -781,7 +783,6 @@ static arena_t	**arenas_map;
 # define	set_arenas_map(x)	(arenas_map = x)
 #else
 
-static thread_key_t arenas_map_key = -1;
 
 static inline arena_t **
 get_arenas_map(void)
@@ -809,14 +810,18 @@ set_arenas_map(arena_t **a)
 	}
 
 	if (arenas_map_key == -1) {
+#ifndef NO_TLS
 		(void)thr_keycreate(_map_key, NULL);
+#endif
 		if (arenas_map != NULL) {
 			_DIAGASSERT(arenas_map == a);
 			arenas_map = NULL;
 		}
 	}
 
+#ifndef NO_TLS
 	thr_setspecific(arenas_map_key, a);
+#endif
 }
 #endif
 



CVS commit: src/lib/libc/stdlib

2020-02-23 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Feb 23 09:53:42 UTC 2020

Modified Files:
src/lib/libc/stdlib: _rand48.c

Log Message:
Change the previous cast from unsigned int to unsigned long

This code produces the same result and is consistent with the previous
lines. Only the least significant 16 bites (unsigned short) are meaningful.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/lib/libc/stdlib/_rand48.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/stdlib/_rand48.c
diff -u src/lib/libc/stdlib/_rand48.c:1.9 src/lib/libc/stdlib/_rand48.c:1.10
--- src/lib/libc/stdlib/_rand48.c:1.9	Sat Feb 22 14:07:57 2020
+++ src/lib/libc/stdlib/_rand48.c	Sun Feb 23 09:53:42 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: _rand48.c,v 1.9 2020/02/22 14:07:57 kamil Exp $	*/
+/*	$NetBSD: _rand48.c,v 1.10 2020/02/23 09:53:42 kamil Exp $	*/
 
 /*
  * Copyright (c) 1993 Martin Birgmeier
@@ -15,7 +15,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: _rand48.c,v 1.9 2020/02/22 14:07:57 kamil Exp $");
+__RCSID("$NetBSD: _rand48.c,v 1.10 2020/02/23 09:53:42 kamil Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include 
@@ -50,9 +50,9 @@ __dorand48(unsigned short xseed[3])
 	accu += (unsigned long) __rand48_mult[1] * (unsigned long) xseed[0];
 	temp[1] = (unsigned short) accu;	/* middle 16 bits */
 	accu >>= sizeof(unsigned short) * 8;
-	accu += (unsigned int) __rand48_mult[0] * (unsigned int) xseed[2];
-	accu += (unsigned int) __rand48_mult[1] * (unsigned int) xseed[1];
-	accu += (unsigned int) __rand48_mult[2] * (unsigned int) xseed[0];
+	accu += (unsigned long) __rand48_mult[0] * (unsigned long) xseed[2];
+	accu += (unsigned long) __rand48_mult[1] * (unsigned long) xseed[1];
+	accu += (unsigned long) __rand48_mult[2] * (unsigned long) xseed[0];
 	xseed[0] = temp[0];
 	xseed[1] = temp[1];
 	xseed[2] = (unsigned short) accu;



CVS commit: src/lib/libc/stdlib

2020-02-22 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Feb 22 14:07:57 UTC 2020

Modified Files:
src/lib/libc/stdlib: _rand48.c

Log Message:
Avoid undefined behavior in the rand48(3) implementation

Instead of implicid promotion to signed int,
explicitly cast the arguments to unsigned int.

_rand48.c:53:27, signed integer overflow:
58989 * 58970 cannot be represented in type 'int'

_rand48.c:53:38, signed integer overflow:
-2093025904 + -1496809120 cannot be represented in type 'int'

_rand48.c:53:57, signed integer overflow:
57068 * 42787 cannot be represented in type 'int'

New and old code produce the same code as tested with:

#include 
#include 

#define COUNT 1000 * 1000

int
main(void)
{
FILE *fp;
int i;

fp = fopen("numbers.txt", "w+");
if (!fp)
abort();

for(i = 0; i < COUNT; i++) {
fprintf(fp, "%f\n", drand48());
fprintf(fp, "%ld\n", lrand48());
fprintf(fp, "%ld\n", mrand48());
}

fclose(fp);

return 0;
}


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/lib/libc/stdlib/_rand48.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/stdlib/_rand48.c
diff -u src/lib/libc/stdlib/_rand48.c:1.8 src/lib/libc/stdlib/_rand48.c:1.9
--- src/lib/libc/stdlib/_rand48.c:1.8	Sat Feb 22 11:24:47 2020
+++ src/lib/libc/stdlib/_rand48.c	Sat Feb 22 14:07:57 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: _rand48.c,v 1.8 2020/02/22 11:24:47 kamil Exp $	*/
+/*	$NetBSD: _rand48.c,v 1.9 2020/02/22 14:07:57 kamil Exp $	*/
 
 /*
  * Copyright (c) 1993 Martin Birgmeier
@@ -15,7 +15,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: _rand48.c,v 1.8 2020/02/22 11:24:47 kamil Exp $");
+__RCSID("$NetBSD: _rand48.c,v 1.9 2020/02/22 14:07:57 kamil Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include 
@@ -50,7 +50,9 @@ __dorand48(unsigned short xseed[3])
 	accu += (unsigned long) __rand48_mult[1] * (unsigned long) xseed[0];
 	temp[1] = (unsigned short) accu;	/* middle 16 bits */
 	accu >>= sizeof(unsigned short) * 8;
-	accu += __rand48_mult[0] * xseed[2] + __rand48_mult[1] * xseed[1] + __rand48_mult[2] * xseed[0];
+	accu += (unsigned int) __rand48_mult[0] * (unsigned int) xseed[2];
+	accu += (unsigned int) __rand48_mult[1] * (unsigned int) xseed[1];
+	accu += (unsigned int) __rand48_mult[2] * (unsigned int) xseed[0];
 	xseed[0] = temp[0];
 	xseed[1] = temp[1];
 	xseed[2] = (unsigned short) accu;



CVS commit: src/lib/libc/stdlib

2020-02-22 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Feb 22 13:20:21 UTC 2020

Modified Files:
src/lib/libc/stdlib: rand48.3

Log Message:
Reorder words to fix grammar

Noted by 


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/libc/stdlib/rand48.3

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/stdlib/rand48.3
diff -u src/lib/libc/stdlib/rand48.3:1.12 src/lib/libc/stdlib/rand48.3:1.13
--- src/lib/libc/stdlib/rand48.3:1.12	Sat Feb 22 11:56:13 2020
+++ src/lib/libc/stdlib/rand48.3	Sat Feb 22 13:20:21 2020
@@ -1,4 +1,4 @@
-.\"	$NetBSD: rand48.3,v 1.12 2020/02/22 11:56:13 kamil Exp $
+.\"	$NetBSD: rand48.3,v 1.13 2020/02/22 13:20:21 kamil Exp $
 .\"
 .\" Copyright (c) 1993 Martin Birgmeier
 .\" All rights reserved.
@@ -98,7 +98,7 @@ On the other hand,
 and
 .Fn jrand48
 use a user-supplied buffer to store the seed r(n), which consists
-of an array of unsigned 3 shorts, where the zeroth member holds the least
+of an array of 3 unsigned shorts, where the zeroth member holds the least
 significant bits.
 .Pp
 All functions share the same multiplicand and addend.



CVS commit: src/lib/libc/stdlib

2020-02-22 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Feb 22 11:56:14 UTC 2020

Modified Files:
src/lib/libc/stdlib: rand48.3

Log Message:
rand48: Document that short integers are unsigned


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/lib/libc/stdlib/rand48.3

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/stdlib/rand48.3
diff -u src/lib/libc/stdlib/rand48.3:1.11 src/lib/libc/stdlib/rand48.3:1.12
--- src/lib/libc/stdlib/rand48.3:1.11	Fri Mar 31 11:43:54 2006
+++ src/lib/libc/stdlib/rand48.3	Sat Feb 22 11:56:13 2020
@@ -1,4 +1,4 @@
-.\"	$NetBSD: rand48.3,v 1.11 2006/03/31 11:43:54 drochner Exp $
+.\"	$NetBSD: rand48.3,v 1.12 2020/02/22 11:56:13 kamil Exp $
 .\"
 .\" Copyright (c) 1993 Martin Birgmeier
 .\" All rights reserved.
@@ -11,7 +11,7 @@
 .\" of any kind. I shall in no event be liable for anything that happens
 .\" to anyone/anything when using this software.
 .\"
-.Dd October 8, 1993
+.Dd February 22, 2020
 .Dt RAND48 3
 .Os
 .Sh NAME
@@ -98,7 +98,7 @@ On the other hand,
 and
 .Fn jrand48
 use a user-supplied buffer to store the seed r(n), which consists
-of an array of 3 shorts, where the zeroth member holds the least
+of an array of unsigned 3 shorts, where the zeroth member holds the least
 significant bits.
 .Pp
 All functions share the same multiplicand and addend.
@@ -120,12 +120,12 @@ also initializes the internal buffer r(n
 .Fn lrand48 ,
 and
 .Fn mrand48 ,
-but here all 48 bits of the seed can be specified in an array of 3 shorts,
+but here all 48 bits of the seed can be specified in an array of 3 unsigned shorts,
 where the zeroth member specifies the lowest bits.
 Again, the constant multiplicand and addend of the algorithm are
 reset to the default values given above.
 .Fn seed48
-returns a pointer to an array of 3 shorts which contains the old seed.
+returns a pointer to an array of 3 unsigned shorts which contains the old seed.
 This array is statically allocated, thus its contents are lost after
 each new call to
 .Fn seed48 .
@@ -145,7 +145,7 @@ and the seed used in
 .Fn lrand48 ,
 and
 .Fn mrand48 .
-An array of 7 shorts is passed as parameter; the first three shorts are
+An array of 7 unsigned shorts is passed as parameter; the first three shorts are
 used to initialize the seed; the second three are used to initialize the
 multiplicand; and the last short is used to initialize the addend.
 It is thus not possible to use values greater than 0x as the addend.



CVS commit: src/lib/libc/stdlib

2020-02-22 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Feb 22 11:24:47 UTC 2020

Modified Files:
src/lib/libc/stdlib: _rand48.c

Log Message:
Improve readability of __dorand48()

Break long lines into shorter instructions per line.

No Functional Change.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/lib/libc/stdlib/_rand48.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/stdlib/_rand48.c
diff -u src/lib/libc/stdlib/_rand48.c:1.7 src/lib/libc/stdlib/_rand48.c:1.8
--- src/lib/libc/stdlib/_rand48.c:1.7	Sun Jun 12 05:21:27 2005
+++ src/lib/libc/stdlib/_rand48.c	Sat Feb 22 11:24:47 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: _rand48.c,v 1.7 2005/06/12 05:21:27 lukem Exp $	*/
+/*	$NetBSD: _rand48.c,v 1.8 2020/02/22 11:24:47 kamil Exp $	*/
 
 /*
  * Copyright (c) 1993 Martin Birgmeier
@@ -15,7 +15,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: _rand48.c,v 1.7 2005/06/12 05:21:27 lukem Exp $");
+__RCSID("$NetBSD: _rand48.c,v 1.8 2020/02/22 11:24:47 kamil Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include 
@@ -42,12 +42,12 @@ __dorand48(unsigned short xseed[3])
 
 	_DIAGASSERT(xseed != NULL);
 
-	accu = (unsigned long) __rand48_mult[0] * (unsigned long) xseed[0] +
-	 (unsigned long) __rand48_add;
+	accu = (unsigned long) __rand48_mult[0] * (unsigned long) xseed[0];
+	accu += (unsigned long) __rand48_add;
 	temp[0] = (unsigned short) accu;	/* lower 16 bits */
 	accu >>= sizeof(unsigned short) * 8;
-	accu += (unsigned long) __rand48_mult[0] * (unsigned long) xseed[1] +
-	 (unsigned long) __rand48_mult[1] * (unsigned long) xseed[0];
+	accu += (unsigned long) __rand48_mult[0] * (unsigned long) xseed[1];
+	accu += (unsigned long) __rand48_mult[1] * (unsigned long) xseed[0];
 	temp[1] = (unsigned short) accu;	/* middle 16 bits */
 	accu >>= sizeof(unsigned short) * 8;
 	accu += __rand48_mult[0] * xseed[2] + __rand48_mult[1] * xseed[1] + __rand48_mult[2] * xseed[0];



CVS commit: src/lib/libc/stdlib

2020-02-22 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Feb 22 10:05:12 UTC 2020

Modified Files:
src/lib/libc/stdlib: _env.c

Log Message:
Avoid NULL pointer arithmetics on environ

_env.c:260:9, pointer expression with base 0 overflowed to 0
_env.c:260:9, load of null pointer of type 'char *'


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/lib/libc/stdlib/_env.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/stdlib/_env.c
diff -u src/lib/libc/stdlib/_env.c:1.9 src/lib/libc/stdlib/_env.c:1.10
--- src/lib/libc/stdlib/_env.c:1.9	Tue Jan 20 18:31:25 2015
+++ src/lib/libc/stdlib/_env.c	Sat Feb 22 10:05:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: _env.c,v 1.9 2015/01/20 18:31:25 christos Exp $ */
+/*	$NetBSD: _env.c,v 1.10 2020/02/22 10:05:12 kamil Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: _env.c,v 1.9 2015/01/20 18:31:25 christos Exp $");
+__RCSID("$NetBSD: _env.c,v 1.10 2020/02/22 10:05:12 kamil Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -257,13 +257,15 @@ __getenvslot(const char *name, size_t l_
 
 	/* Search for an existing environment variable of the given name. */
 	num_entries = 0;
-	while (environ[num_entries] != NULL) {
-		if (strncmp(environ[num_entries], name, l_name) == 0 &&
-		environ[num_entries][l_name] == '=') {
-			/* We found a match. */
-			return num_entries;
+	if (environ != NULL) {
+		while (environ[num_entries] != NULL) {
+			if (strncmp(environ[num_entries], name, l_name) == 0 &&
+			environ[num_entries][l_name] == '=') {
+/* We found a match. */
+return num_entries;
+			}
+			num_entries ++;
 		}
-		num_entries ++;
 	}
 
 	/* No match found, return if we don't want to allocate a new slot. */



CVS commit: src/lib/libc/stdlib

2020-01-13 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Mon Jan 13 19:14:02 UTC 2020

Modified Files:
src/lib/libc/stdlib: jemalloc.c

Log Message:
Fix aarch64 definition in old jemalloc

There is no platform-specific reason for avoiding TLS. The tiny
allocations should be aligned the same as small allocations for ABI
reasons.


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/lib/libc/stdlib/jemalloc.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/stdlib/jemalloc.c
diff -u src/lib/libc/stdlib/jemalloc.c:1.46 src/lib/libc/stdlib/jemalloc.c:1.47
--- src/lib/libc/stdlib/jemalloc.c:1.46	Thu Mar 28 15:05:03 2019
+++ src/lib/libc/stdlib/jemalloc.c	Mon Jan 13 19:14:02 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: jemalloc.c,v 1.46 2019/03/28 15:05:03 christos Exp $	*/
+/*	$NetBSD: jemalloc.c,v 1.47 2020/01/13 19:14:02 joerg Exp $	*/
 
 /*-
  * Copyright (C) 2006,2007 Jason Evans .
@@ -118,7 +118,7 @@
 
 #include 
 /* __FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.147 2007/06/15 22:00:16 jasone Exp $"); */ 
-__RCSID("$NetBSD: jemalloc.c,v 1.46 2019/03/28 15:05:03 christos Exp $");
+__RCSID("$NetBSD: jemalloc.c,v 1.47 2020/01/13 19:14:02 joerg Exp $");
 
 #ifdef __FreeBSD__
 #include "libc_private.h"
@@ -216,7 +216,7 @@ __RCSID("$NetBSD: jemalloc.c,v 1.46 2019
 #ifdef __aarch64__
 #  define QUANTUM_2POW_MIN	4
 #  define SIZEOF_PTR_2POW	3
-#  define NO_TLS
+#  define TINY_MIN_2POW		3
 #endif
 #ifdef __alpha__
 #  define QUANTUM_2POW_MIN	4



CVS commit: src/lib/libc/stdlib

2020-01-13 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Mon Jan 13 19:14:38 UTC 2020

Modified Files:
src/lib/libc/stdlib: jemalloc.c

Log Message:
Fix atfork malloc handling to include all the locks in old jemalloc.


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/lib/libc/stdlib/jemalloc.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/stdlib/jemalloc.c
diff -u src/lib/libc/stdlib/jemalloc.c:1.47 src/lib/libc/stdlib/jemalloc.c:1.48
--- src/lib/libc/stdlib/jemalloc.c:1.47	Mon Jan 13 19:14:02 2020
+++ src/lib/libc/stdlib/jemalloc.c	Mon Jan 13 19:14:37 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: jemalloc.c,v 1.47 2020/01/13 19:14:02 joerg Exp $	*/
+/*	$NetBSD: jemalloc.c,v 1.48 2020/01/13 19:14:37 joerg Exp $	*/
 
 /*-
  * Copyright (C) 2006,2007 Jason Evans .
@@ -118,7 +118,7 @@
 
 #include 
 /* __FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.147 2007/06/15 22:00:16 jasone Exp $"); */ 
-__RCSID("$NetBSD: jemalloc.c,v 1.47 2020/01/13 19:14:02 joerg Exp $");
+__RCSID("$NetBSD: jemalloc.c,v 1.48 2020/01/13 19:14:37 joerg Exp $");
 
 #ifdef __FreeBSD__
 #include "libc_private.h"
@@ -3986,16 +3986,17 @@ _malloc_prefork(void)
 	unsigned i;
 
 	/* Acquire all mutexes in a safe order. */
-
+	malloc_mutex_lock(_lock);
 	malloc_mutex_lock(_mtx);
 	for (i = 0; i < narenas; i++) {
 		if (arenas[i] != NULL)
 			malloc_mutex_lock([i]->mtx);
 	}
-
-	malloc_mutex_lock(_mtx);
-
 	malloc_mutex_lock(_mtx);
+	malloc_mutex_lock(_mtx);
+#ifdef USE_BRK
+	malloc_mutex_lock(_mtx);
+#endif
 }
 
 void
@@ -4004,16 +4005,18 @@ _malloc_postfork(void)
 	unsigned i;
 
 	/* Release all mutexes, now that fork() has completed. */
-
-	malloc_mutex_unlock(_mtx);
-
+#ifdef USE_BRK
+	malloc_mutex_unlock(_mtx);
+#endif
 	malloc_mutex_unlock(_mtx);
+	malloc_mutex_unlock(_mtx);
 
-	for (i = 0; i < narenas; i++) {
+	for (i = narenas; i-- > 0; ) {
 		if (arenas[i] != NULL)
 			malloc_mutex_unlock([i]->mtx);
 	}
 	malloc_mutex_unlock(_mtx);
+	malloc_mutex_unlock(_lock);
 }
 
 /*



CVS commit: src/lib/libc/stdlib

2019-12-06 Thread Niclas Rosenvik
Module Name:src
Committed By:   nros
Date:   Fri Dec  6 16:19:32 UTC 2019

Modified Files:
src/lib/libc/stdlib: posix_memalign.3

Log Message:
Fix manpage due to updated aligned_alloc behavior

Since aligned_alloc does not demand that size is to be multiple of alignment
anymore, don't make that claim in the man page.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/libc/stdlib/posix_memalign.3

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/stdlib/posix_memalign.3
diff -u src/lib/libc/stdlib/posix_memalign.3:1.6 src/lib/libc/stdlib/posix_memalign.3:1.7
--- src/lib/libc/stdlib/posix_memalign.3:1.6	Fri Jul 27 15:15:30 2018
+++ src/lib/libc/stdlib/posix_memalign.3	Fri Dec  6 16:19:32 2019
@@ -1,4 +1,4 @@
-.\"	$NetBSD: posix_memalign.3,v 1.6 2018/07/27 15:15:30 maya Exp $
+.\"	$NetBSD: posix_memalign.3,v 1.7 2019/12/06 16:19:32 nros Exp $
 .\"
 .\" Copyright (C) 2006 Jason Evans .
 .\" All rights reserved.
@@ -113,17 +113,6 @@ The
 parameter is not at least as large as
 .Fn sizeof "void *" .
 .El
-.Pp
-The
-.Fn aligned_alloc
-function will also fail if
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The
-.Fa size
-parameter is not an integer multiple of
-.Fa alignment .
-.El
 .Sh SEE ALSO
 .Xr free 3 ,
 .Xr malloc 3 ,



CVS commit: src/lib/libc/stdlib

2019-03-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Mar 28 15:05:03 UTC 2019

Modified Files:
src/lib/libc/stdlib: jemalloc.c

Log Message:
fix compilation for non _REENTRANT


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/lib/libc/stdlib/jemalloc.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/stdlib/jemalloc.c
diff -u src/lib/libc/stdlib/jemalloc.c:1.45 src/lib/libc/stdlib/jemalloc.c:1.46
--- src/lib/libc/stdlib/jemalloc.c:1.45	Wed Jul 25 16:05:35 2018
+++ src/lib/libc/stdlib/jemalloc.c	Thu Mar 28 11:05:03 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: jemalloc.c,v 1.45 2018/07/25 20:05:35 kamil Exp $	*/
+/*	$NetBSD: jemalloc.c,v 1.46 2019/03/28 15:05:03 christos Exp $	*/
 
 /*-
  * Copyright (C) 2006,2007 Jason Evans .
@@ -118,7 +118,7 @@
 
 #include 
 /* __FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.147 2007/06/15 22:00:16 jasone Exp $"); */ 
-__RCSID("$NetBSD: jemalloc.c,v 1.45 2018/07/25 20:05:35 kamil Exp $");
+__RCSID("$NetBSD: jemalloc.c,v 1.46 2019/03/28 15:05:03 christos Exp $");
 
 #ifdef __FreeBSD__
 #include "libc_private.h"
@@ -704,7 +704,9 @@ static chunk_tree_t	huge;
  * base_pages_alloc() also uses sbrk(), but cannot lock chunks_mtx (doing so
  * could cause recursive lock acquisition).
  */
+#ifdef _REENTRANT
 static malloc_mutex_t	brk_mtx;
+#endif
 /* Result of first sbrk(0) call. */
 static void		*brk_base;
 /* Current end of brk, or ((void *)-1) if brk is exhausted. */



CVS commit: src/lib/libc/stdlib

2019-03-04 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Mar  4 17:30:33 UTC 2019

Modified Files:
src/lib/libc/stdlib: Makefile.inc

Log Message:
Hook for jemalloc


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 src/lib/libc/stdlib/Makefile.inc

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/stdlib/Makefile.inc
diff -u src/lib/libc/stdlib/Makefile.inc:1.94 src/lib/libc/stdlib/Makefile.inc:1.95
--- src/lib/libc/stdlib/Makefile.inc:1.94	Fri Jan  5 15:51:13 2018
+++ src/lib/libc/stdlib/Makefile.inc	Mon Mar  4 12:30:33 2019
@@ -1,11 +1,11 @@
-#	$NetBSD: Makefile.inc,v 1.94 2018/01/05 20:51:13 snj Exp $
+#	$NetBSD: Makefile.inc,v 1.95 2019/03/04 17:30:33 christos Exp $
 #	from: @(#)Makefile.inc	8.3 (Berkeley) 2/4/95
 
 # stdlib sources
 .PATH: ${ARCHDIR}/stdlib ${.CURDIR}/stdlib
 
 SRCS+=	_env.c _rand48.c \
-	a64l.c abort.c aligned_alloc.c atexit.c atof.c atoi.c atol.c atoll.c \
+	a64l.c abort.c atexit.c atof.c atoi.c atol.c atoll.c \
 	bsearch.c cxa_thread_atexit.c drand48.c exit.c \
 	getenv.c getopt.c getopt_long.c getsubopt.c \
 	hcreate.c heapsort.c imaxdiv.c insque.c jrand48.c l64a.c lldiv.c \
@@ -26,11 +26,15 @@ SRCS+=	div.c ldiv.c imaxdiv.c
 SRCS+= erand48_ieee754.c
 
 .if ${RUMPRUN} != "yes"
-.if (${USE_JEMALLOC} != "no")
-SRCS+=	jemalloc.c
-.else
+.   if (${USE_JEMALLOC} != "no")
+.  if ${HAVE_JEMALLOC} > 100
+. include "${NETBSDSRCDIR}/external/bsd/jemalloc/lib/Makefile.inc"
+.  else
+SRCS+=	jemalloc.c aligned_alloc.c
+.  endif 
+.   else
 SRCS+=	malloc.c
-.endif
+.   endif
 .endif
 
 CPPFLAGS.strtol.c+=	-I${LIBCDIR}/../../common/lib/libc/stdlib



CVS commit: src/lib/libc/stdlib

2018-12-09 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Dec  9 20:29:53 UTC 2018

Modified Files:
src/lib/libc/stdlib: getopt_long.3

Log Message:
fix grammar.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/lib/libc/stdlib/getopt_long.3

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/stdlib/getopt_long.3
diff -u src/lib/libc/stdlib/getopt_long.3:1.19 src/lib/libc/stdlib/getopt_long.3:1.20
--- src/lib/libc/stdlib/getopt_long.3:1.19	Mon Jul  3 17:32:50 2017
+++ src/lib/libc/stdlib/getopt_long.3	Sun Dec  9 15:29:53 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: getopt_long.3,v 1.19 2017/07/03 21:32:50 wiz Exp $
+.\"	$NetBSD: getopt_long.3,v 1.20 2018/12/09 20:29:53 christos Exp $
 .\"
 .\" Copyright (c) 1988, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\" @(#)getopt.3	8.5 (Berkeley) 4/27/95
 .\"
-.Dd July 2, 2007
+.Dd December 9, 2018
 .Dt GETOPT_LONG 3
 .Os
 .Sh NAME
@@ -113,7 +113,7 @@ The
 field should be one of:
 .Bl -tag -width "optional_argument"
 .It Li no_argument
-no argument to the option is expect.
+no argument to the option is expected.
 .It Li required_argument
 an argument to the option is required.
 .It Li optional_argument



CVS commit: src/lib/libc/stdlib

2018-12-05 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Dec  6 06:29:56 UTC 2018

Modified Files:
src/lib/libc/stdlib: strtonum.c

Log Message:
Correct handling of minval > maxval in strtonum(3)

The original implementation in OpenBSD returns "invalid" and avoids reading
the input string. The replaced behavior was interpreting the input string
ignoring the invalid arguments.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libc/stdlib/strtonum.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/stdlib/strtonum.c
diff -u src/lib/libc/stdlib/strtonum.c:1.5 src/lib/libc/stdlib/strtonum.c:1.6
--- src/lib/libc/stdlib/strtonum.c:1.5	Thu Jan  4 20:57:29 2018
+++ src/lib/libc/stdlib/strtonum.c	Thu Dec  6 06:29:56 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: strtonum.c,v 1.5 2018/01/04 20:57:29 kamil Exp $	*/
+/*	$NetBSD: strtonum.c,v 1.6 2018/12/06 06:29:56 kamil Exp $	*/
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -29,7 +29,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: strtonum.c,v 1.5 2018/01/04 20:57:29 kamil Exp $");
+__RCSID("$NetBSD: strtonum.c,v 1.6 2018/12/06 06:29:56 kamil Exp $");
 
 #include "namespace.h"
 
@@ -50,6 +50,11 @@ strtonum(const char *nptr, long long min
 	if (errstr == NULL)
 		errstr = 
 
+	if (minval > maxval) {
+		*errstr = "invalid";
+		return 0;
+	}
+
 	rv = (long long)strtoi(nptr, NULL, 10, minval, maxval, );
 
 	if (e == 0) {



CVS commit: src/lib/libc/stdlib

2018-08-30 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Aug 30 12:06:06 UTC 2018

Modified Files:
src/lib/libc/stdlib: getsubopt.c

Log Message:
Allow being compiled as a tool.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/lib/libc/stdlib/getsubopt.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/stdlib/getsubopt.c
diff -u src/lib/libc/stdlib/getsubopt.c:1.9 src/lib/libc/stdlib/getsubopt.c:1.10
--- src/lib/libc/stdlib/getsubopt.c:1.9	Mon Jun 25 18:32:45 2012
+++ src/lib/libc/stdlib/getsubopt.c	Thu Aug 30 08:06:06 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: getsubopt.c,v 1.9 2012/06/25 22:32:45 abs Exp $	*/
+/*	$NetBSD: getsubopt.c,v 1.10 2018/08/30 12:06:06 christos Exp $	*/
 
 /*-
  * Copyright (c) 1990, 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[] = "@(#)getsubopt.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: getsubopt.c,v 1.9 2012/06/25 22:32:45 abs Exp $");
+__RCSID("$NetBSD: getsubopt.c,v 1.10 2018/08/30 12:06:06 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 



CVS commit: src/lib/libc/stdlib

2018-08-15 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Aug 15 10:49:47 UTC 2018

Modified Files:
src/lib/libc/stdlib: getsubopt.3

Log Message:
PR standards/53525: move getsubopt to stdlib.h


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/lib/libc/stdlib/getsubopt.3

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/stdlib/getsubopt.3
diff -u src/lib/libc/stdlib/getsubopt.3:1.15 src/lib/libc/stdlib/getsubopt.3:1.16
--- src/lib/libc/stdlib/getsubopt.3:1.15	Mon Jul  3 21:32:50 2017
+++ src/lib/libc/stdlib/getsubopt.3	Wed Aug 15 10:49:47 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: getsubopt.3,v 1.15 2017/07/03 21:32:50 wiz Exp $
+.\"	$NetBSD: getsubopt.3,v 1.16 2018/08/15 10:49:47 martin Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\" @(#)getsubopt.3	8.1 (Berkeley) 6/9/93
 .\"
-.Dd November 17, 2009
+.Dd August 15, 2018
 .Dt GETSUBOPT 3
 .Os
 .Sh NAME
@@ -38,7 +38,7 @@
 .Sh LIBRARY
 .Lb libc
 .Sh SYNOPSIS
-.In unistd.h
+.In stdlib.h
 .Vt extern char *suboptarg
 .Ft int
 .Fn getsubopt "char **optionp" "char * const *tokens" "char **valuep"



CVS commit: src/lib/libc/stdlib

2018-07-27 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Fri Jul 27 15:15:30 UTC 2018

Modified Files:
src/lib/libc/stdlib: posix_memalign.3

Log Message:
it's C18, not C17.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libc/stdlib/posix_memalign.3

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/stdlib/posix_memalign.3
diff -u src/lib/libc/stdlib/posix_memalign.3:1.5 src/lib/libc/stdlib/posix_memalign.3:1.6
--- src/lib/libc/stdlib/posix_memalign.3:1.5	Fri Jul 27 14:34:44 2018
+++ src/lib/libc/stdlib/posix_memalign.3	Fri Jul 27 15:15:30 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: posix_memalign.3,v 1.5 2018/07/27 14:34:44 maya Exp $
+.\"	$NetBSD: posix_memalign.3,v 1.6 2018/07/27 15:15:30 maya Exp $
 .\"
 .\" Copyright (C) 2006 Jason Evans .
 .\" All rights reserved.
@@ -137,7 +137,7 @@ function conforms to
 The
 .Fn aligned_alloc
 function conforms to
-.St -isoC-2017 .
+.St -isoC-2018 .
 .Sh HISTORY
 .St -isoC-2011
 required size to be an integer multiple of alignment.



CVS commit: src/lib/libc/stdlib

2018-07-27 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Fri Jul 27 14:34:44 UTC 2018

Modified Files:
src/lib/libc/stdlib: posix_memalign.3

Log Message:
Claim C17 (although I'm unsure), add a note about C11's requirements.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libc/stdlib/posix_memalign.3

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/stdlib/posix_memalign.3
diff -u src/lib/libc/stdlib/posix_memalign.3:1.4 src/lib/libc/stdlib/posix_memalign.3:1.5
--- src/lib/libc/stdlib/posix_memalign.3:1.4	Fri Jul 27 13:08:47 2018
+++ src/lib/libc/stdlib/posix_memalign.3	Fri Jul 27 14:34:44 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: posix_memalign.3,v 1.4 2018/07/27 13:08:47 maya Exp $
+.\"	$NetBSD: posix_memalign.3,v 1.5 2018/07/27 14:34:44 maya Exp $
 .\"
 .\" Copyright (C) 2006 Jason Evans .
 .\" All rights reserved.
@@ -137,4 +137,8 @@ function conforms to
 The
 .Fn aligned_alloc
 function conforms to
-.St -isoC-2011 .
+.St -isoC-2017 .
+.Sh HISTORY
+.St -isoC-2011
+required size to be an integer multiple of alignment.
+This requirement was removed in later standards.



CVS commit: src/lib/libc/stdlib

2018-07-27 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Fri Jul 27 13:08:47 UTC 2018

Modified Files:
src/lib/libc/stdlib: aligned_alloc.c posix_memalign.3

Log Message:
C17 conformance: aligned_alloc's size doesn't need to be a multiple of
alignment any more.

Thanks Joseph Myers for the heads up.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libc/stdlib/aligned_alloc.c
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/stdlib/posix_memalign.3

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/stdlib/aligned_alloc.c
diff -u src/lib/libc/stdlib/aligned_alloc.c:1.1 src/lib/libc/stdlib/aligned_alloc.c:1.2
--- src/lib/libc/stdlib/aligned_alloc.c:1.1	Sat Nov  7 16:21:42 2015
+++ src/lib/libc/stdlib/aligned_alloc.c	Fri Jul 27 13:08:47 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: aligned_alloc.c,v 1.1 2015/11/07 16:21:42 nros Exp $ */
+/* $NetBSD: aligned_alloc.c,v 1.2 2018/07/27 13:08:47 maya Exp $ */
 
 /*-
  * Copyright (C) 2015 The NetBSD Foundation, Inc.
@@ -42,11 +42,9 @@ aligned_alloc(size_t alignment, size_t s
 int err;
 	
 /*
- * Check that alignment is a power of 2
- * and that size is an integer multiple of alignment.
+ * Check that alignment is a power of 2.
  */
-if (alignment == 0 || ((alignment - 1) & alignment) != 0 ||
-(size & (alignment-1)) != 0) {
+if (alignment == 0 || ((alignment - 1) & alignment) != 0) {
 errno = EINVAL;
 return NULL;
 }

Index: src/lib/libc/stdlib/posix_memalign.3
diff -u src/lib/libc/stdlib/posix_memalign.3:1.3 src/lib/libc/stdlib/posix_memalign.3:1.4
--- src/lib/libc/stdlib/posix_memalign.3:1.3	Sat Nov  7 18:47:26 2015
+++ src/lib/libc/stdlib/posix_memalign.3	Fri Jul 27 13:08:47 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: posix_memalign.3,v 1.3 2015/11/07 18:47:26 wiz Exp $
+.\"	$NetBSD: posix_memalign.3,v 1.4 2018/07/27 13:08:47 maya Exp $
 .\"
 .\" Copyright (C) 2006 Jason Evans .
 .\" All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\" FreeBSD: src/lib/libc/stdlib/posix_memalign.3,v 1.3 2007/03/28 04:32:51 jasone Exp
 .\"
-.Dd October 30, 2015
+.Dd July 27, 2018
 .Dt POSIX_MEMALIGN 3
 .Os
 .Sh NAME
@@ -65,10 +65,7 @@ bytes of memory such that the allocation
 .Fa alignment .
 The requested
 .Fa alignment
-must be a power of 2 and
-.Fa size
-must be a integer multiple of
-.Fa alignment .
+must be a power of 2.
 .Pp
 Memory that is allocated via
 .Fn posix_memalign



CVS commit: src/lib/libc/stdlib

2018-07-25 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Jul 25 20:05:35 UTC 2018

Modified Files:
src/lib/libc/stdlib: jemalloc.c

Log Message:
Avoid undefined behavior in left bit shift in jemalloc(3)

Change the type of shifted value to unsigned to prevent altering the
signedness bit.

jemalloc.c:1707:14, left shift of 1 by 31 places cannot be represented in type 
'int'
jemalloc.c:1724:15, left shift of 1 by 31 places cannot be represented in type 
'int'
jemalloc.c:1840:28, left shift of 1 by 31 places cannot be represented in type 
'int'

Detected with micro-UBSan in the user mode.


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/lib/libc/stdlib/jemalloc.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/stdlib/jemalloc.c
diff -u src/lib/libc/stdlib/jemalloc.c:1.44 src/lib/libc/stdlib/jemalloc.c:1.45
--- src/lib/libc/stdlib/jemalloc.c:1.44	Fri Dec  1 22:47:06 2017
+++ src/lib/libc/stdlib/jemalloc.c	Wed Jul 25 20:05:35 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: jemalloc.c,v 1.44 2017/12/01 22:47:06 mrg Exp $	*/
+/*	$NetBSD: jemalloc.c,v 1.45 2018/07/25 20:05:35 kamil Exp $	*/
 
 /*-
  * Copyright (C) 2006,2007 Jason Evans .
@@ -118,7 +118,7 @@
 
 #include 
 /* __FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.147 2007/06/15 22:00:16 jasone Exp $"); */ 
-__RCSID("$NetBSD: jemalloc.c,v 1.44 2017/12/01 22:47:06 mrg Exp $");
+__RCSID("$NetBSD: jemalloc.c,v 1.45 2018/07/25 20:05:35 kamil Exp $");
 
 #ifdef __FreeBSD__
 #include "libc_private.h"
@@ -1704,7 +1704,7 @@ arena_run_reg_alloc(arena_run_t *run, ar
 		+ (bin->reg_size * regind));
 
 		/* Clear bit. */
-		mask ^= (1 << bit);
+		mask ^= (1U << bit);
 		run->regs_mask[i] = mask;
 
 		return (ret);
@@ -1721,7 +1721,7 @@ arena_run_reg_alloc(arena_run_t *run, ar
 			+ (bin->reg_size * regind));
 
 			/* Clear bit. */
-			mask ^= (1 << bit);
+			mask ^= (1U << bit);
 			run->regs_mask[i] = mask;
 
 			/*
@@ -1836,8 +1836,8 @@ arena_run_reg_dalloc(arena_run_t *run, a
 	if (elm < run->regs_minelm)
 		run->regs_minelm = elm;
 	bit = regind - (elm << (SIZEOF_INT_2POW + 3));
-	assert((run->regs_mask[elm] & (1 << bit)) == 0);
-	run->regs_mask[elm] |= (1 << bit);
+	assert((run->regs_mask[elm] & (1U << bit)) == 0);
+	run->regs_mask[elm] |= (1U << bit);
 #undef SIZE_INV
 #undef SIZE_INV_SHIFT
 }



CVS commit: src/lib/libc/stdlib

2018-06-13 Thread Eitan Adler
Module Name:src
Committed By:   eadler
Date:   Wed Jun 13 09:38:32 UTC 2018

Modified Files:
src/lib/libc/stdlib: atoi.3 atoi.c

Log Message:
libc: remove explicit cast NULL in atoi

There isn't any reason to cast NULL so just remove it. A similar change
was already made in DragonFly and FreeBSD (by me).

ok fly@


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/lib/libc/stdlib/atoi.3
cvs rdiff -u -r1.14 -r1.15 src/lib/libc/stdlib/atoi.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/stdlib/atoi.3
diff -u src/lib/libc/stdlib/atoi.3:1.10 src/lib/libc/stdlib/atoi.3:1.11
--- src/lib/libc/stdlib/atoi.3:1.10	Thu Aug  7 16:43:38 2003
+++ src/lib/libc/stdlib/atoi.3	Wed Jun 13 09:38:32 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: atoi.3,v 1.10 2003/08/07 16:43:38 agc Exp $
+.\"	$NetBSD: atoi.3,v 1.11 2018/06/13 09:38:32 eadler Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -33,7 +33,7 @@
 .\"
 .\" from: @(#)atoi.3	8.1 (Berkeley) 6/4/93
 .\"
-.Dd June 4, 1993
+.Dd June 13, 2018
 .Dt ATOI 3
 .Os
 .Sh NAME
@@ -58,7 +58,7 @@ representation.
 .Pp
 It is equivalent to:
 .Bd -literal -offset indent
-(int)strtol(nptr, (char **)NULL, 10);
+(int)strtol(nptr, NULL, 10);
 .Ed
 .Sh SEE ALSO
 .Xr atof 3 ,

Index: src/lib/libc/stdlib/atoi.c
diff -u src/lib/libc/stdlib/atoi.c:1.14 src/lib/libc/stdlib/atoi.c:1.15
--- src/lib/libc/stdlib/atoi.c:1.14	Sun Jan  7 15:28:33 2018
+++ src/lib/libc/stdlib/atoi.c	Wed Jun 13 09:38:32 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: atoi.c,v 1.14 2018/01/07 15:28:33 kamil Exp $	*/
+/*	$NetBSD: atoi.c,v 1.15 2018/06/13 09:38:32 eadler Exp $	*/
 
 /*
  * Copyright (c) 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)atoi.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: atoi.c,v 1.14 2018/01/07 15:28:33 kamil Exp $");
+__RCSID("$NetBSD: atoi.c,v 1.15 2018/06/13 09:38:32 eadler Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -46,5 +46,5 @@ atoi(const char *str)
 {
 	_DIAGASSERT(str != NULL);
 
-	return((int)strtol(str, (char **)NULL, 10));
+	return((int)strtol(str, NULL, 10));
 }



CVS commit: src/lib/libc/stdlib

2018-05-23 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Wed May 23 21:21:27 UTC 2018

Modified Files:
src/lib/libc/stdlib: merge.c

Log Message:
Simplify to avoid pointless null pointer arithmetic.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/lib/libc/stdlib/merge.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/stdlib/merge.c
diff -u src/lib/libc/stdlib/merge.c:1.15 src/lib/libc/stdlib/merge.c:1.16
--- src/lib/libc/stdlib/merge.c:1.15	Sat Aug 12 01:10:04 2017
+++ src/lib/libc/stdlib/merge.c	Wed May 23 21:21:27 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: merge.c,v 1.15 2017/08/12 01:10:04 ginsbach Exp $	*/
+/*	$NetBSD: merge.c,v 1.16 2018/05/23 21:21:27 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "from: @(#)merge.c	8.2 (Berkeley) 2/14/94";
 #else
-__RCSID("$NetBSD: merge.c,v 1.15 2017/08/12 01:10:04 ginsbach Exp $");
+__RCSID("$NetBSD: merge.c,v 1.16 2018/05/23 21:21:27 joerg Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -101,8 +101,7 @@ static void insertionsort(u_char *, size
  */
 /* Assumption: PSIZE is a power of 2. */
 #define EVAL(p) ((u_char **)(void *)	\
-((u_char *)0 +			\
-(((u_char *)(void *)(p) + PSIZE - 1 - (u_char *) 0) & ~(PSIZE - 1
+(((u_char *)(void *)(p) + PSIZE - 1 - (u_char *) 0) & ~(PSIZE - 1)))
 
 /*
  * Arguments are as for qsort.



CVS commit: src/lib/libc/stdlib

2017-12-07 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Thu Dec  7 22:19:17 UTC 2017

Modified Files:
src/lib/libc/stdlib: strfmon.3

Log Message:
Fix obvious typo (cut or whatever) - there's only one value that
specifies the number of digits after the decimal point (oh, sorry, the
"radix character") the other specifies the number before...

While here, add a little more info on the effects of using the #n value.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/lib/libc/stdlib/strfmon.3

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/stdlib/strfmon.3
diff -u src/lib/libc/stdlib/strfmon.3:1.7 src/lib/libc/stdlib/strfmon.3:1.8
--- src/lib/libc/stdlib/strfmon.3:1.7	Wed Aug 16 17:41:36 2017
+++ src/lib/libc/stdlib/strfmon.3	Thu Dec  7 22:19:17 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: strfmon.3,v 1.7 2017/08/16 17:41:36 wiz Exp $
+.\"	$NetBSD: strfmon.3,v 1.8 2017/12/07 22:19:17 kre Exp $
 .\"
 .\" Copyright (c) 2001 Jeroen Ruigrok van der Werven 
 .\" All rights reserved.
@@ -26,7 +26,7 @@
 .\"
 .\" 	From: FreeBSD: Id: strfmon.3,v 1.7 2003/01/06 06:21:25 tjr Exp
 .\"
-.Dd August 15, 2017
+.Dd December 7, 2017
 .Dt STRFMON 3
 .Os
 .Sh NAME
@@ -102,7 +102,13 @@ By default, there is no minimum width.
 A
 .Sq Cm #
 sign followed by a decimal number specifying the maximum
-expected number of digits after the radix character.
+expected number of digits before the radix character.
+When this option is used, values that do not exceed the
+specified number of digits are formatted so they will be
+correctly aligned with other values printed using the same
+format.
+This includes always leaving space for a possible sign
+indicator, even if none is needed for a particular value.
 .It
 A
 .Sq Cm \&.



CVS commit: src/lib/libc/stdlib

2017-12-01 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Fri Dec  1 22:47:06 UTC 2017

Modified Files:
src/lib/libc/stdlib: jemalloc.c

Log Message:
normalise some indentation.  NFC.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/lib/libc/stdlib/jemalloc.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/stdlib/jemalloc.c
diff -u src/lib/libc/stdlib/jemalloc.c:1.43 src/lib/libc/stdlib/jemalloc.c:1.44
--- src/lib/libc/stdlib/jemalloc.c:1.43	Thu Nov 16 13:54:00 2017
+++ src/lib/libc/stdlib/jemalloc.c	Fri Dec  1 22:47:06 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: jemalloc.c,v 1.43 2017/11/16 13:54:00 skrll Exp $	*/
+/*	$NetBSD: jemalloc.c,v 1.44 2017/12/01 22:47:06 mrg Exp $	*/
 
 /*-
  * Copyright (C) 2006,2007 Jason Evans .
@@ -118,7 +118,7 @@
 
 #include 
 /* __FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.147 2007/06/15 22:00:16 jasone Exp $"); */ 
-__RCSID("$NetBSD: jemalloc.c,v 1.43 2017/11/16 13:54:00 skrll Exp $");
+__RCSID("$NetBSD: jemalloc.c,v 1.44 2017/12/01 22:47:06 mrg Exp $");
 
 #ifdef __FreeBSD__
 #include "libc_private.h"
@@ -276,19 +276,19 @@ __RCSID("$NetBSD: jemalloc.c,v 1.43 2017
 #  define USE_BRK
 #endif
 #if defined(__mips__) || defined(__riscv__)
-# ifdef _LP64
-#  define SIZEOF_PTR_2POW	3
-#  define TINY_MIN_2POW		3
-# else
-#  define SIZEOF_PTR_2POW	2
-# endif
-# define QUANTUM_2POW_MIN	4
-# define USE_BRK
+#  ifdef _LP64
+#define SIZEOF_PTR_2POW	3
+#define TINY_MIN_2POW	3
+#  else
+#define SIZEOF_PTR_2POW	2
+#  endif
+#  define QUANTUM_2POW_MIN	4
+#  define USE_BRK
 #endif
 #ifdef __hppa__ 
-#  define QUANTUM_2POW_MIN 4
-#  define TINY_MIN_2POW4
-#  define SIZEOF_PTR_2POW  2
+#  define QUANTUM_2POW_MIN	4
+#  define TINY_MIN_2POW		4
+#  define SIZEOF_PTR_2POW	2
 #  define USE_BRK   
 #endif   
 



CVS commit: src/lib/libc/stdlib

2017-11-27 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Mon Nov 27 23:54:28 UTC 2017

Modified Files:
src/lib/libc/stdlib: strfmon.c

Log Message:
use calloc rather than malloc + memset 0


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/libc/stdlib/strfmon.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/stdlib/strfmon.c
diff -u src/lib/libc/stdlib/strfmon.c:1.12 src/lib/libc/stdlib/strfmon.c:1.13
--- src/lib/libc/stdlib/strfmon.c:1.12	Mon Nov 27 22:43:07 2017
+++ src/lib/libc/stdlib/strfmon.c	Mon Nov 27 23:54:28 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: strfmon.c,v 1.12 2017/11/27 22:43:07 christos Exp $	*/
+/*	$NetBSD: strfmon.c,v 1.13 2017/11/27 23:54:28 maya Exp $	*/
 
 /*-
  * Copyright (c) 2001 Alexey Zelkin 
@@ -32,7 +32,7 @@
 #if 0
 __FBSDID("$FreeBSD: src/lib/libc/stdlib/strfmon.c,v 1.14 2003/03/20 08:18:55 ache Exp $");
 #else
-__RCSID("$NetBSD: strfmon.c,v 1.12 2017/11/27 22:43:07 christos Exp $");
+__RCSID("$NetBSD: strfmon.c,v 1.13 2017/11/27 23:54:28 maya Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -556,12 +556,11 @@ __format_grouped_double(struct lconv *lc
 
 	/* make sure that we've enough space for result string */
 	bufsize = avalue_size * 2 + 1;
-	rslt = malloc(bufsize);
+	rslt = calloc(1, bufsize);
 	if (rslt == NULL) {
 		free(avalue);
 		return (NULL);
 	}
-	memset(rslt, 0, bufsize);
 	bufend = rslt + bufsize - 1;	/* reserve space for trailing '\0' */
 
 	/* skip spaces at beggining */



CVS commit: src/lib/libc/stdlib

2017-11-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Nov 27 22:43:07 UTC 2017

Modified Files:
src/lib/libc/stdlib: strfmon.c

Log Message:
Fix various bugs with strfmon:
- Avoid out of bounds access for the currency_symbol[3] when the symbol
  is shorter (as it happens with the C locale where it is empty)
- Don't compare pointers to NUL, it is not helpful.
- Make the default sep_by_space 1 as suggested in:
  https://ftp.gnu.org/old-gnu/Manuals/glibc-2.2.3/html_node/libc_111.html
- Use the correct number of bytes for memmove(3)

XXX: pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/lib/libc/stdlib/strfmon.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/stdlib/strfmon.c
diff -u src/lib/libc/stdlib/strfmon.c:1.11 src/lib/libc/stdlib/strfmon.c:1.12
--- src/lib/libc/stdlib/strfmon.c:1.11	Wed Aug 16 09:53:20 2017
+++ src/lib/libc/stdlib/strfmon.c	Mon Nov 27 17:43:07 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: strfmon.c,v 1.11 2017/08/16 13:53:20 joerg Exp $	*/
+/*	$NetBSD: strfmon.c,v 1.12 2017/11/27 22:43:07 christos Exp $	*/
 
 /*-
  * Copyright (c) 2001 Alexey Zelkin 
@@ -32,7 +32,7 @@
 #if 0
 __FBSDID("$FreeBSD: src/lib/libc/stdlib/strfmon.c,v 1.14 2003/03/20 08:18:55 ache Exp $");
 #else
-__RCSID("$NetBSD: strfmon.c,v 1.11 2017/08/16 13:53:20 joerg Exp $");
+__RCSID("$NetBSD: strfmon.c,v 1.12 2017/11/27 22:43:07 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -241,8 +241,12 @@ vstrfmon_l(char * __restrict s, size_t m
 			free(currency_symbol);
 		if (flags & USE_INTL_CURRENCY) {
 			currency_symbol = strdup(lc->int_curr_symbol);
-			if (currency_symbol != NULL)
-space_char = *(currency_symbol+3);
+			if (currency_symbol != NULL &&
+			strlen(currency_symbol) > 3) {
+space_char = currency_symbol[3];
+currency_symbol[3] = '\0';
+			}
+
 		} else
 			currency_symbol = strdup(lc->currency_symbol);
 
@@ -418,7 +422,7 @@ __setup_vars(struct lconv *lc, int flags
 		*cs_precedes = lc->int_n_cs_precedes;
 		*sep_by_space = lc->int_n_sep_by_space;
 		*sign_posn = (flags & PARENTH_POSN) ? 0 : lc->int_n_sign_posn;
-		*signstr = (lc->negative_sign == '\0') ? "-"
+		*signstr = (*lc->negative_sign == '\0') ? "-"
 		: lc->negative_sign;
 	} else if (flags & USE_INTL_CURRENCY) {
 		*cs_precedes = lc->int_p_cs_precedes;
@@ -429,7 +433,7 @@ __setup_vars(struct lconv *lc, int flags
 		*cs_precedes = lc->n_cs_precedes;
 		*sep_by_space = lc->n_sep_by_space;
 		*sign_posn = (flags & PARENTH_POSN) ? 0 : lc->n_sign_posn;
-		*signstr = (lc->negative_sign == '\0') ? "-"
+		*signstr = (*lc->negative_sign == '\0') ? "-"
 		: lc->negative_sign;
 	} else {
 		*cs_precedes = lc->p_cs_precedes;
@@ -438,11 +442,11 @@ __setup_vars(struct lconv *lc, int flags
 		*signstr = lc->positive_sign;
 	}
 
-	/* Set defult values for unspecified information. */
+	/* Set default values for unspecified information. */
 	if (*cs_precedes != 0)
 		*cs_precedes = 1;
 	if ((unsigned char)*sep_by_space == NBCHAR_MAX)
-		*sep_by_space = 0;
+		*sep_by_space = 1;
 	if ((unsigned char)*sign_posn == NBCHAR_MAX)
 		*sign_posn = 0;
 }
@@ -615,8 +619,7 @@ __format_grouped_double(struct lconv *lc
 		memset(bufend, pad_char, (size_t) padded);
 	}
 
-	bufsize = bufsize - (bufend - rslt) + 1;
-	memmove(rslt, bufend, bufsize);
+	memmove(rslt, bufend, bufend - rslt + 1);
 	free(avalue);
 	return (rslt);
 }



CVS commit: src/lib/libc/stdlib

2017-11-16 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Nov 16 13:54:00 UTC 2017

Modified Files:
src/lib/libc/stdlib: jemalloc.c

Log Message:
The HPPA architectures (1.1 and 2.0) both define quadruple-word (128-bit)
floating point types.  Adjust alignment to match.


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/lib/libc/stdlib/jemalloc.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/stdlib/jemalloc.c
diff -u src/lib/libc/stdlib/jemalloc.c:1.42 src/lib/libc/stdlib/jemalloc.c:1.43
--- src/lib/libc/stdlib/jemalloc.c:1.42	Fri May 19 19:55:16 2017
+++ src/lib/libc/stdlib/jemalloc.c	Thu Nov 16 13:54:00 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: jemalloc.c,v 1.42 2017/05/19 19:55:16 christos Exp $	*/
+/*	$NetBSD: jemalloc.c,v 1.43 2017/11/16 13:54:00 skrll Exp $	*/
 
 /*-
  * Copyright (C) 2006,2007 Jason Evans .
@@ -118,7 +118,7 @@
 
 #include 
 /* __FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.147 2007/06/15 22:00:16 jasone Exp $"); */ 
-__RCSID("$NetBSD: jemalloc.c,v 1.42 2017/05/19 19:55:16 christos Exp $");
+__RCSID("$NetBSD: jemalloc.c,v 1.43 2017/11/16 13:54:00 skrll Exp $");
 
 #ifdef __FreeBSD__
 #include "libc_private.h"
@@ -287,6 +287,7 @@ __RCSID("$NetBSD: jemalloc.c,v 1.42 2017
 #endif
 #ifdef __hppa__ 
 #  define QUANTUM_2POW_MIN 4
+#  define TINY_MIN_2POW4
 #  define SIZEOF_PTR_2POW  2
 #  define USE_BRK   
 #endif   



CVS commit: src/lib/libc/stdlib

2017-11-06 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Mon Nov  6 14:26:03 UTC 2017

Modified Files:
src/lib/libc/stdlib: atexit.c

Log Message:
Assert that __cxa_atexit is not used with NULL as DSO. Don't use
__cxa_atexit directly from atexit, they have different behavior.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/lib/libc/stdlib/atexit.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/stdlib/atexit.c
diff -u src/lib/libc/stdlib/atexit.c:1.31 src/lib/libc/stdlib/atexit.c:1.32
--- src/lib/libc/stdlib/atexit.c:1.31	Thu Nov  2 19:39:33 2017
+++ src/lib/libc/stdlib/atexit.c	Mon Nov  6 14:26:03 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: atexit.c,v 1.31 2017/11/02 19:39:33 kamil Exp $	*/
+/*	$NetBSD: atexit.c,v 1.32 2017/11/06 14:26:03 joerg Exp $	*/
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: atexit.c,v 1.31 2017/11/02 19:39:33 kamil Exp $");
+__RCSID("$NetBSD: atexit.c,v 1.32 2017/11/06 14:26:03 joerg Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "reentrant.h"
@@ -142,12 +142,12 @@ __aeabi_atexit(void *arg, void (*func)(v
 int
 __aeabi_atexit(void *arg, void (*func)(void *), void *dso)
 {
-	return __cxa_atexit(func, arg, dso);
+	return (__cxa_atexit(func, arg, dso));
 }
 #endif
 
-int
-__cxa_atexit(void (*func)(void *), void *arg, void *dso)
+static int
+__cxa_atexit_internal(void (*func)(void *), void *arg, void *dso)
 {
 	struct atexit_handler *ah;
 
@@ -172,6 +172,13 @@ __cxa_atexit(void (*func)(void *), void 
 	return (0);
 }
 
+int
+__cxa_atexit(void (*func)(void *), void *arg, void *dso)
+{
+	_DIAGASSERT(dso != NULL);
+	return (__cxa_atexit_internal(func, arg, dso));
+}
+
 /*
  * Run the list of atexit handlers.  If dso is NULL, run all of them,
  * otherwise run only those matching the specified dso.
@@ -255,5 +262,5 @@ int
 atexit(void (*func)(void))
 {
 
-	return (__cxa_atexit((void (*)(void *))func, NULL, NULL));
+	return (__cxa_atexit_internal((void (*)(void *))func, NULL, NULL));
 }



CVS commit: src/lib/libc/stdlib

2017-11-02 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Nov  2 19:39:33 UTC 2017

Modified Files:
src/lib/libc/stdlib: atexit.c

Log Message:
Revert previous on demand.

Rationale:

The DSO handle is a required part of the (external) __cxa_atexit interface.
The atexit mapping is an implementation detail and not part of the public
interface. Doing it directly creates UB as it involves casting function
pointers between incompatible types.

  -- Joerg


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/lib/libc/stdlib/atexit.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/stdlib/atexit.c
diff -u src/lib/libc/stdlib/atexit.c:1.30 src/lib/libc/stdlib/atexit.c:1.31
--- src/lib/libc/stdlib/atexit.c:1.30	Thu Nov  2 18:37:14 2017
+++ src/lib/libc/stdlib/atexit.c	Thu Nov  2 19:39:33 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: atexit.c,v 1.30 2017/11/02 18:37:14 kamil Exp $	*/
+/*	$NetBSD: atexit.c,v 1.31 2017/11/02 19:39:33 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: atexit.c,v 1.30 2017/11/02 18:37:14 kamil Exp $");
+__RCSID("$NetBSD: atexit.c,v 1.31 2017/11/02 19:39:33 kamil Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "reentrant.h"
@@ -205,7 +205,7 @@ again:
 		if (dso == NULL || dso == ah->ah_dso || ah->ah_atexit == NULL) {
 			if (ah->ah_atexit != NULL) {
 void *p = atexit_handler_stack;
-if (ah->ah_dso != NULL || ah->ah_arg != NULL) {
+if (ah->ah_dso != NULL) {
 	cxa_func = ah->ah_cxa_atexit;
 	ah->ah_cxa_atexit = NULL;
 	(*cxa_func)(ah->ah_arg);



CVS commit: src/lib/libc/stdlib

2017-11-02 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Nov  2 18:37:15 UTC 2017

Modified Files:
src/lib/libc/stdlib: atexit.c

Log Message:
Correct handling of __cxa_atexit(a,b,NULL) in libc

In the NetBSD implementation and suggested by Itanium C++ ABI, we wrap
the atexit(x) call as __cxa_atexit(x,NULL,NULL).

__cxa_atexit() is an internal function for the usage of C++.

Correct a bug that __cxa_atexit(x,y,NULL) is handled in the same way as
atexit(x) (which is simplified to __cxa_atexit(x,NULL,NULL).

This misbehavior has been detected in the Thread Sanitizer port to NetBSD.

Patch reviewed by 

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/lib/libc/stdlib/atexit.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/stdlib/atexit.c
diff -u src/lib/libc/stdlib/atexit.c:1.29 src/lib/libc/stdlib/atexit.c:1.30
--- src/lib/libc/stdlib/atexit.c:1.29	Sun Apr 19 18:15:26 2015
+++ src/lib/libc/stdlib/atexit.c	Thu Nov  2 18:37:14 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: atexit.c,v 1.29 2015/04/19 18:15:26 joerg Exp $	*/
+/*	$NetBSD: atexit.c,v 1.30 2017/11/02 18:37:14 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: atexit.c,v 1.29 2015/04/19 18:15:26 joerg Exp $");
+__RCSID("$NetBSD: atexit.c,v 1.30 2017/11/02 18:37:14 kamil Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "reentrant.h"
@@ -205,7 +205,7 @@ again:
 		if (dso == NULL || dso == ah->ah_dso || ah->ah_atexit == NULL) {
 			if (ah->ah_atexit != NULL) {
 void *p = atexit_handler_stack;
-if (ah->ah_dso != NULL) {
+if (ah->ah_dso != NULL || ah->ah_arg != NULL) {
 	cxa_func = ah->ah_cxa_atexit;
 	ah->ah_cxa_atexit = NULL;
 	(*cxa_func)(ah->ah_arg);



CVS commit: src/lib/libc/stdlib

2017-10-25 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Wed Oct 25 17:09:47 UTC 2017

Modified Files:
src/lib/libc/stdlib: jemalloc.3

Log Message:
Add malloc.conf to the NAME section
Remove Pp before Bd at few places


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/lib/libc/stdlib/jemalloc.3

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/stdlib/jemalloc.3
diff -u src/lib/libc/stdlib/jemalloc.3:1.9 src/lib/libc/stdlib/jemalloc.3:1.10
--- src/lib/libc/stdlib/jemalloc.3:1.9	Sat Jul 20 21:39:57 2013
+++ src/lib/libc/stdlib/jemalloc.3	Wed Oct 25 17:09:47 2017
@@ -38,7 +38,8 @@
 .Dt JEMALLOC 3
 .Os
 .Sh NAME
-.Nm jemalloc
+.Nm jemalloc ,
+.Nm malloc.conf
 .Nd the default system allocator
 .Sh LIBRARY
 .Lb libc
@@ -160,7 +161,6 @@ the source code:
 .Bd -literal -offset indent
 _malloc_options = "X";
 .Ed
-.Pp
 .It Em Z
 Each byte of new memory allocated by
 .Fn malloc ,
@@ -228,7 +228,6 @@ determine all metadata regarding small a
 Small objects are managed in groups by page runs.
 Each run maintains a bitmap that tracks which regions are in use.
 Allocation requests can be grouped as follows.
-.Pp
 .Bl -bullet -offset 3n
 .It
 Allocation requests that are no more than half the quantum (see the
@@ -306,7 +305,6 @@ allocation functions.
 .El
 .Sh EXAMPLES
 To dump core whenever a problem occurs:
-.Pp
 .Bd -literal -offset indent
 ln -s 'A' /etc/malloc.conf
 .Ed



CVS commit: src/lib/libc/stdlib

2017-10-07 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Oct  7 21:15:48 UTC 2017

Modified Files:
src/lib/libc/stdlib: reallocarray.c

Log Message:
remove recallocarray


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/lib/libc/stdlib/reallocarray.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/stdlib/reallocarray.c
diff -u src/lib/libc/stdlib/reallocarray.c:1.8 src/lib/libc/stdlib/reallocarray.c:1.9
--- src/lib/libc/stdlib/reallocarray.c:1.8	Sat Oct  7 15:38:35 2017
+++ src/lib/libc/stdlib/reallocarray.c	Sat Oct  7 17:15:48 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: reallocarray.c,v 1.8 2017/10/07 19:38:35 christos Exp $	*/
+/*	$NetBSD: reallocarray.c,v 1.9 2017/10/07 21:15:48 christos Exp $	*/
 /*	$OpenBSD: reallocarray.c,v 1.1 2014/05/08 21:43:49 deraadt Exp $	*/
 
 /*-
@@ -31,11 +31,10 @@
  */
 
 #include 
-__RCSID("$NetBSD: reallocarray.c,v 1.8 2017/10/07 19:38:35 christos Exp $");
+__RCSID("$NetBSD: reallocarray.c,v 1.9 2017/10/07 21:15:48 christos Exp $");
 
 #define _OPENBSD_SOURCE
 #include 
-#include 
 #include 
 
 void *
@@ -52,15 +51,3 @@ reallocarray(void *optr, size_t nmemb, s
 	errno = e;
 	return NULL;
 }
-
-void *
-recallocarray(void *optr, size_t omemb, size_t nmemb, size_t size)
-{
-	char *nptr = reallocarray(optr, nmemb, size);
-
-	if (nptr == NULL || omemb >= nmemb)
-		return nptr;
-
-	memset(nptr + omemb * size, 0, (nmemb - omemb) * size);
-	return nptr;
-}



CVS commit: src/lib/libc/stdlib

2017-10-07 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Oct  7 19:38:35 UTC 2017

Modified Files:
src/lib/libc/stdlib: reallocarray.c

Log Message:
add recallocarray


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/lib/libc/stdlib/reallocarray.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/stdlib/reallocarray.c
diff -u src/lib/libc/stdlib/reallocarray.c:1.7 src/lib/libc/stdlib/reallocarray.c:1.8
--- src/lib/libc/stdlib/reallocarray.c:1.7	Wed Apr  6 07:07:58 2016
+++ src/lib/libc/stdlib/reallocarray.c	Sat Oct  7 15:38:35 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: reallocarray.c,v 1.7 2016/04/06 11:07:58 roy Exp $	*/
+/*	$NetBSD: reallocarray.c,v 1.8 2017/10/07 19:38:35 christos Exp $	*/
 /*	$OpenBSD: reallocarray.c,v 1.1 2014/05/08 21:43:49 deraadt Exp $	*/
 
 /*-
@@ -31,10 +31,11 @@
  */
 
 #include 
-__RCSID("$NetBSD: reallocarray.c,v 1.7 2016/04/06 11:07:58 roy Exp $");
+__RCSID("$NetBSD: reallocarray.c,v 1.8 2017/10/07 19:38:35 christos Exp $");
 
 #define _OPENBSD_SOURCE
 #include 
+#include 
 #include 
 
 void *
@@ -51,3 +52,15 @@ reallocarray(void *optr, size_t nmemb, s
 	errno = e;
 	return NULL;
 }
+
+void *
+recallocarray(void *optr, size_t omemb, size_t nmemb, size_t size)
+{
+	char *nptr = reallocarray(optr, nmemb, size);
+
+	if (nptr == NULL || omemb >= nmemb)
+		return nptr;
+
+	memset(nptr + omemb * size, 0, (nmemb - omemb) * size);
+	return nptr;
+}



CVS commit: src/lib/libc/stdlib

2017-09-09 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Sep  9 12:28:19 UTC 2017

Modified Files:
src/lib/libc/stdlib: ptsname.3

Log Message:
Correct the documentatin of ptsname_r(3)

This function returns "int" not "char *": errno on failure, 0 on success.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/lib/libc/stdlib/ptsname.3

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/stdlib/ptsname.3
diff -u src/lib/libc/stdlib/ptsname.3:1.10 src/lib/libc/stdlib/ptsname.3:1.11
--- src/lib/libc/stdlib/ptsname.3:1.10	Mon Jul  3 21:32:50 2017
+++ src/lib/libc/stdlib/ptsname.3	Sat Sep  9 12:28:19 2017
@@ -1,4 +1,4 @@
-.\" $NetBSD: ptsname.3,v 1.10 2017/07/03 21:32:50 wiz Exp $
+.\" $NetBSD: ptsname.3,v 1.11 2017/09/09 12:28:19 kamil Exp $
 .\"
 .\" Copyright (c) 2004 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd January 7, 2014
+.Dd September 9, 2017
 .Dt PTSNAME 3
 .Os
 .Sh NAME
@@ -40,7 +40,7 @@
 .In stdlib.h
 .Ft char *
 .Fn ptsname "int masterfd"
-.Ft char *
+.Ft int
 .Fn ptsname_r "int masterfd" "char *buf" "size_t buflen"
 .Sh DESCRIPTION
 The



CVS commit: src/lib/libc/stdlib

2017-08-16 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Wed Aug 16 17:41:36 UTC 2017

Modified Files:
src/lib/libc/stdlib: strfmon.3

Log Message:
Typo fix.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/libc/stdlib/strfmon.3

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/stdlib/strfmon.3
diff -u src/lib/libc/stdlib/strfmon.3:1.6 src/lib/libc/stdlib/strfmon.3:1.7
--- src/lib/libc/stdlib/strfmon.3:1.6	Wed Aug 16 13:53:20 2017
+++ src/lib/libc/stdlib/strfmon.3	Wed Aug 16 17:41:36 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: strfmon.3,v 1.6 2017/08/16 13:53:20 joerg Exp $
+.\"	$NetBSD: strfmon.3,v 1.7 2017/08/16 17:41:36 wiz Exp $
 .\"
 .\" Copyright (c) 2001 Jeroen Ruigrok van der Werven 
 .\" All rights reserved.
@@ -54,9 +54,9 @@ bytes are placed into the array.
 The
 .Fn strfmon_l
 function behaves the same as
-.fn strfmon ,
+.Fn strfmon ,
 but uses the locale
-.Fa loc 
+.Fa loc
 instead of the process global locale.
 .Pp
 The format string is composed of zero or more directives:



CVS commit: src/lib/libc/stdlib

2017-08-11 Thread Brian Ginsbach
Module Name:src
Committed By:   ginsbach
Date:   Sat Aug 12 01:10:04 UTC 2017

Modified Files:
src/lib/libc/stdlib: merge.c

Log Message:
PR lib/50316: Gracefully handle a zero number of members argument.

Taken from FreeBSD (which fixed this same issue long ago).

XXX: pullup-8
XXX: pullup-7
XXX: pullup-6


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/lib/libc/stdlib/merge.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/stdlib/merge.c
diff -u src/lib/libc/stdlib/merge.c:1.14 src/lib/libc/stdlib/merge.c:1.15
--- src/lib/libc/stdlib/merge.c:1.14	Tue Mar 13 21:13:48 2012
+++ src/lib/libc/stdlib/merge.c	Sat Aug 12 01:10:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: merge.c,v 1.14 2012/03/13 21:13:48 christos Exp $	*/
+/*	$NetBSD: merge.c,v 1.15 2017/08/12 01:10:04 ginsbach Exp $	*/
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "from: @(#)merge.c	8.2 (Berkeley) 2/14/94";
 #else
-__RCSID("$NetBSD: merge.c,v 1.14 2012/03/13 21:13:48 christos Exp $");
+__RCSID("$NetBSD: merge.c,v 1.15 2017/08/12 01:10:04 ginsbach Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -125,6 +125,9 @@ mergesort(void *base, size_t nmemb, size
 		return (-1);
 	}
 
+	if (nmemb == 0)
+		return (0);
+
 	/*
 	 * XXX
 	 * Stupid subtraction for the Cray.



CVS commit: src/lib/libc/stdlib

2017-07-14 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Fri Jul 14 19:24:52 UTC 2017

Modified Files:
src/lib/libc/stdlib: exit.c

Log Message:
Drop TLS variant checks, emutls is enough for VAX and Sun2.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/lib/libc/stdlib/exit.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/stdlib/exit.c
diff -u src/lib/libc/stdlib/exit.c:1.16 src/lib/libc/stdlib/exit.c:1.17
--- src/lib/libc/stdlib/exit.c:1.16	Tue Jul 11 15:21:35 2017
+++ src/lib/libc/stdlib/exit.c	Fri Jul 14 19:24:52 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: exit.c,v 1.16 2017/07/11 15:21:35 joerg Exp $	*/
+/*	$NetBSD: exit.c,v 1.17 2017/07/14 19:24:52 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -34,11 +34,10 @@
 #if 0
 static char sccsid[] = "@(#)exit.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: exit.c,v 1.16 2017/07/11 15:21:35 joerg Exp $");
+__RCSID("$NetBSD: exit.c,v 1.17 2017/07/14 19:24:52 joerg Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
-#include 
 #include 
 #include 
 #ifdef _LIBC
@@ -56,10 +55,8 @@ exit(int status)
 {
 
 #ifdef _LIBC
-#  if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II)
 	if (__cxa_thread_atexit_used)
 		__cxa_thread_run_atexit();
-#  endif
 	__cxa_finalize(NULL);
 #endif
 	if (__cleanup)



CVS commit: src/lib/libc/stdlib

2017-05-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri May 19 19:55:16 UTC 2017

Modified Files:
src/lib/libc/stdlib: jemalloc.c

Log Message:
remove accidental __strong_alias additions, noticed by coypu.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/lib/libc/stdlib/jemalloc.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/stdlib/jemalloc.c
diff -u src/lib/libc/stdlib/jemalloc.c:1.41 src/lib/libc/stdlib/jemalloc.c:1.42
--- src/lib/libc/stdlib/jemalloc.c:1.41	Fri May 19 15:51:10 2017
+++ src/lib/libc/stdlib/jemalloc.c	Fri May 19 15:55:16 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: jemalloc.c,v 1.41 2017/05/19 19:51:10 christos Exp $	*/
+/*	$NetBSD: jemalloc.c,v 1.42 2017/05/19 19:55:16 christos Exp $	*/
 
 /*-
  * Copyright (C) 2006,2007 Jason Evans .
@@ -118,7 +118,7 @@
 
 #include 
 /* __FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.147 2007/06/15 22:00:16 jasone Exp $"); */ 
-__RCSID("$NetBSD: jemalloc.c,v 1.41 2017/05/19 19:51:10 christos Exp $");
+__RCSID("$NetBSD: jemalloc.c,v 1.42 2017/05/19 19:55:16 christos Exp $");
 
 #ifdef __FreeBSD__
 #include "libc_private.h"
@@ -162,10 +162,6 @@ __RCSID("$NetBSD: jemalloc.c,v 1.41 2017
 #ifdef __NetBSD__
 #  include 
 #  include "extern.h"
-__strong_alias(__libc_malloc,malloc)
-__strong_alias(__libc_realloc,realloc)
-__strong_alias(__libc_calloc,calloc)
-__strong_alias(__libc_free,free)
 
 #define STRERROR_R(a, b, c)	strerror_r_ss(a, b, c);
 #endif



CVS commit: src/lib/libc/stdlib

2017-05-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri May 19 19:51:11 UTC 2017

Modified Files:
src/lib/libc/stdlib: jemalloc.c

Log Message:
use strerror_r_ss()


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/lib/libc/stdlib/jemalloc.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/stdlib/jemalloc.c
diff -u src/lib/libc/stdlib/jemalloc.c:1.40 src/lib/libc/stdlib/jemalloc.c:1.41
--- src/lib/libc/stdlib/jemalloc.c:1.40	Tue Apr 12 14:07:08 2016
+++ src/lib/libc/stdlib/jemalloc.c	Fri May 19 15:51:10 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: jemalloc.c,v 1.40 2016/04/12 18:07:08 joerg Exp $	*/
+/*	$NetBSD: jemalloc.c,v 1.41 2017/05/19 19:51:10 christos Exp $	*/
 
 /*-
  * Copyright (C) 2006,2007 Jason Evans .
@@ -118,7 +118,7 @@
 
 #include 
 /* __FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.147 2007/06/15 22:00:16 jasone Exp $"); */ 
-__RCSID("$NetBSD: jemalloc.c,v 1.40 2016/04/12 18:07:08 joerg Exp $");
+__RCSID("$NetBSD: jemalloc.c,v 1.41 2017/05/19 19:51:10 christos Exp $");
 
 #ifdef __FreeBSD__
 #include "libc_private.h"
@@ -162,28 +162,12 @@ __RCSID("$NetBSD: jemalloc.c,v 1.40 2016
 #ifdef __NetBSD__
 #  include 
 #  include "extern.h"
+__strong_alias(__libc_malloc,malloc)
+__strong_alias(__libc_realloc,realloc)
+__strong_alias(__libc_calloc,calloc)
+__strong_alias(__libc_free,free)
 
-#define STRERROR_R(a, b, c)	__strerror_r(a, b, c);
-/*
- * A non localized version of strerror, that avoids bringing in
- * stdio and the locale code. All the malloc messages are in English
- * so why bother?
- */
-static int
-__strerror_r(int e, char *s, size_t l)
-{
-	int rval;
-	size_t slen;
-
-	if (e >= 0 && e < sys_nerr) {
-		slen = strlcpy(s, sys_errlist[e], l);
-		rval = 0;
-	} else {
-		slen = snprintf_ss(s, l, "Unknown error %u", e);
-		rval = EINVAL;
-	}
-	return slen >= l ? ERANGE : rval;
-}
+#define STRERROR_R(a, b, c)	strerror_r_ss(a, b, c);
 #endif
 
 #ifdef __FreeBSD__



CVS commit: src/lib/libc/stdlib

2017-05-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri May 19 19:48:19 UTC 2017

Modified Files:
src/lib/libc/stdlib: qsort.c

Log Message:
The BSD qsort() performs tail recursion elimination on the second
side of the array being partitioned to save on stack space.  Greater
savings can be gained by choosing recursion for the smaller side
of the partition and eliminating recursion for the larger side.
This also results in a small but measurable performance gain.
(From OpenBSD)


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/lib/libc/stdlib/qsort.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/stdlib/qsort.c
diff -u src/lib/libc/stdlib/qsort.c:1.22 src/lib/libc/stdlib/qsort.c:1.23
--- src/lib/libc/stdlib/qsort.c:1.22	Sat May 26 17:47:05 2012
+++ src/lib/libc/stdlib/qsort.c	Fri May 19 15:48:19 2017
@@ -1,5 +1,4 @@
-/*	$NetBSD: qsort.c,v 1.22 2012/05/26 21:47:05 christos Exp $	*/
-
+/*	$NetBSD: qsort.c,v 1.23 2017/05/19 19:48:19 christos Exp $	*/
 /*-
  * Copyright (c) 1992, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -34,7 +33,7 @@
 #if 0
 static char sccsid[] = "@(#)qsort.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: qsort.c,v 1.22 2012/05/26 21:47:05 christos Exp $");
+__RCSID("$NetBSD: qsort.c,v 1.23 2017/05/19 19:48:19 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -102,7 +101,7 @@ qsort(void *a, size_t n, size_t es,
 int (*cmp)(const void *, const void *))
 {
 	char *pa, *pb, *pc, *pd, *pl, *pm, *pn;
-	size_t d, r;
+	size_t d, r, s;
 	int swaptype, cmp_result;
 
 	_DIAGASSERT(a != NULL || n == 0 || es == 0);
@@ -159,13 +158,28 @@ loop:	SWAPINIT(a, es);
 	vecswap(a, pb - r, r);
 	r = min((size_t)(pd - pc), pn - pd - es);
 	vecswap(pb, pn - r, r);
-	if ((r = pb - pa) > es)
-		qsort(a, r / es, es, cmp);
-	if ((r = pd - pc) > es) { 
-		/* Iterate rather than recurse to save stack space */
-		a = pn - r;
-		n = r / es;
-		goto loop;
+	/*
+	 * To save stack space we sort the smaller side of the partition first
+	 * using recursion and eliminate tail recursion for the larger side.
+	 */
+	r = pb - pa;
+	s = pd - pc;
+	if (r < s) {
+		/* Recurse for 1st side, iterate for 2nd side. */
+		if (s > es) {
+			if (r > es)
+qsort(a, r / es, es, cmp);
+			a = pn - s;
+			n = s / es;
+			goto loop;
+		}
+	} else {
+		/* Recurse for 2nd side, iterate for 1st side. */
+		if (r > es) {
+			if (s > es)
+qsort(pn - s, s / es, es, cmp);
+			n = r / es;
+			goto loop;
+		}
 	}
-/*		qsort(pn - r, r / es, es, cmp);*/
 }



CVS commit: src/lib/libc/stdlib

2017-02-07 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Feb  7 22:25:25 UTC 2017

Modified Files:
src/lib/libc/stdlib: hcreate.3

Log Message:
PR/51958: Ngie Cooper: ESRCH error description in hcreate(3) contains typo
for action


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/lib/libc/stdlib/hcreate.3

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/stdlib/hcreate.3
diff -u src/lib/libc/stdlib/hcreate.3:1.13 src/lib/libc/stdlib/hcreate.3:1.14
--- src/lib/libc/stdlib/hcreate.3:1.13	Sun Jul 20 16:17:21 2014
+++ src/lib/libc/stdlib/hcreate.3	Tue Feb  7 17:25:25 2017
@@ -1,4 +1,4 @@
-.\" 	$NetBSD: hcreate.3,v 1.13 2014/07/20 20:17:21 christos Exp $
+.\" 	$NetBSD: hcreate.3,v 1.14 2017/02/07 22:25:25 christos Exp $
 .\"
 .\" Copyright (c) 1999 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd July 20, 2014
+.Dd February 7, 2017
 .Dt HCREATE 3
 .Os
 .Sh NAME
@@ -274,7 +274,7 @@ The
 and
 .Fn hsearch_r
 functions will also fail if the action is
-.Dv SEARCH
+.Dv FIND
 and the element is not found:
 .Bl -tag -width Er
 .It Bq Er ESRCH



CVS commit: src/lib/libc/stdlib

2017-01-12 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jan 13 04:18:54 UTC 2017

Modified Files:
src/lib/libc/stdlib: malloc.c

Log Message:
use getpagesize(3).


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/lib/libc/stdlib/malloc.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/stdlib/malloc.c
diff -u src/lib/libc/stdlib/malloc.c:1.58 src/lib/libc/stdlib/malloc.c:1.59
--- src/lib/libc/stdlib/malloc.c:1.58	Wed Jan 11 21:00:42 2017
+++ src/lib/libc/stdlib/malloc.c	Thu Jan 12 23:18:54 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: malloc.c,v 1.58 2017/01/12 02:00:42 christos Exp $	*/
+/*	$NetBSD: malloc.c,v 1.59 2017/01/13 04:18:54 christos Exp $	*/
 
 /*
  * 
@@ -93,7 +93,7 @@ int utrace(const char *, void *, size_t)
 # include 
 # include "extern.h"
 # if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: malloc.c,v 1.58 2017/01/12 02:00:42 christos Exp $");
+__RCSID("$NetBSD: malloc.c,v 1.59 2017/01/13 04:18:54 christos Exp $");
 # endif /* LIBC_SCCS and not lint */
 # include 
 # ifdef _REENTRANT
@@ -458,11 +458,7 @@ malloc_init(void)
 /*
  * Compute page-size related variables.
  */
-#ifdef _LIBC
-malloc_pagesize = (size_t)sysconf(_SC_PAGESIZE);
-#else
-malloc_pagesize = 4096;
-#endif
+malloc_pagesize = getpagesize();
 malloc_pagemask = malloc_pagesize - 1;
 for (malloc_pageshift = 0;
 	 (1UL << malloc_pageshift) != malloc_pagesize;



CVS commit: src/lib/libc/stdlib

2017-01-11 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jan 12 02:00:42 UTC 2017

Modified Files:
src/lib/libc/stdlib: malloc.c

Log Message:
Avoid sysconf: __sysconf -> sysctlgetmibinfo -> strtoimax -> locale, etc.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/lib/libc/stdlib/malloc.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/stdlib/malloc.c
diff -u src/lib/libc/stdlib/malloc.c:1.57 src/lib/libc/stdlib/malloc.c:1.58
--- src/lib/libc/stdlib/malloc.c:1.57	Wed Jan 11 20:02:09 2017
+++ src/lib/libc/stdlib/malloc.c	Wed Jan 11 21:00:42 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: malloc.c,v 1.57 2017/01/12 01:02:09 christos Exp $	*/
+/*	$NetBSD: malloc.c,v 1.58 2017/01/12 02:00:42 christos Exp $	*/
 
 /*
  * 
@@ -93,7 +93,7 @@ int utrace(const char *, void *, size_t)
 # include 
 # include "extern.h"
 # if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: malloc.c,v 1.57 2017/01/12 01:02:09 christos Exp $");
+__RCSID("$NetBSD: malloc.c,v 1.58 2017/01/12 02:00:42 christos Exp $");
 # endif /* LIBC_SCCS and not lint */
 # include 
 # ifdef _REENTRANT
@@ -458,7 +458,11 @@ malloc_init(void)
 /*
  * Compute page-size related variables.
  */
+#ifdef _LIBC
 malloc_pagesize = (size_t)sysconf(_SC_PAGESIZE);
+#else
+malloc_pagesize = 4096;
+#endif
 malloc_pagemask = malloc_pagesize - 1;
 for (malloc_pageshift = 0;
 	 (1UL << malloc_pageshift) != malloc_pagesize;



CVS commit: src/lib/libc/stdlib

2017-01-11 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jan 12 01:02:09 UTC 2017

Modified Files:
src/lib/libc/stdlib: malloc.c

Log Message:
make this smaller.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/lib/libc/stdlib/malloc.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/stdlib/malloc.c
diff -u src/lib/libc/stdlib/malloc.c:1.56 src/lib/libc/stdlib/malloc.c:1.57
--- src/lib/libc/stdlib/malloc.c:1.56	Thu Sep 18 09:58:20 2014
+++ src/lib/libc/stdlib/malloc.c	Wed Jan 11 20:02:09 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: malloc.c,v 1.56 2014/09/18 13:58:20 christos Exp $	*/
+/*	$NetBSD: malloc.c,v 1.57 2017/01/12 01:02:09 christos Exp $	*/
 
 /*
  * 
@@ -84,21 +84,27 @@ void utrace(struct ut *, int);
 
 #include 
 #if defined(__NetBSD__)
-#   define malloc_minsize   16U
-#   define HAS_UTRACE
-#   define UTRACE_LABEL "malloc",
-#include 
-#include "extern.h"
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: malloc.c,v 1.56 2014/09/18 13:58:20 christos Exp $");
-#endif /* LIBC_SCCS and not lint */
+# define malloc_minsize   16U
+# ifdef _LIBC
+#  define HAS_UTRACE
+#  define UTRACE_LABEL "malloc",
 int utrace(const char *, void *, size_t);
-
-#include 
+# endif
+# include 
+# include "extern.h"
+# if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: malloc.c,v 1.57 2017/01/12 01:02:09 christos Exp $");
+# endif /* LIBC_SCCS and not lint */
+# include 
+# ifdef _REENTRANT
 extern int __isthreaded;
 static mutex_t thread_lock = MUTEX_INITIALIZER;
-#define _MALLOC_LOCK()	if (__isthreaded) mutex_lock(_lock);
-#define _MALLOC_UNLOCK()	if (__isthreaded) mutex_unlock(_lock);
+#  define _MALLOC_LOCK()	if (__isthreaded) mutex_lock(_lock);
+#  define _MALLOC_UNLOCK()	if (__isthreaded) mutex_unlock(_lock);
+# else
+#  define _MALLOC_LOCK()	
+#  define _MALLOC_UNLOCK()
+# endif
 #endif /* __NetBSD__ */
 
 #if defined(__sparc__) && defined(sun)
@@ -472,8 +478,10 @@ malloc_init(void)
 		continue;
 	b[j] = '\0';
 	p = b;
+#ifdef _LIBC
 	} else if (i == 1 && issetugid() == 0) {
 	p = getenv("MALLOC_OPTIONS");
+#endif
 	} else if (i == 1) {
 	continue;
 	} else {



CVS commit: src/lib/libc/stdlib

2016-12-16 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Sat Dec 17 06:17:16 UTC 2016

Modified Files:
src/lib/libc/stdlib: div.3

Log Message:
Fix typo


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/lib/libc/stdlib/div.3

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/stdlib/div.3
diff -u src/lib/libc/stdlib/div.3:1.14 src/lib/libc/stdlib/div.3:1.15
--- src/lib/libc/stdlib/div.3:1.14	Tue May  3 09:36:24 2011
+++ src/lib/libc/stdlib/div.3	Sat Dec 17 06:17:16 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: div.3,v 1.14 2011/05/03 09:36:24 wiz Exp $
+.\"	$NetBSD: div.3,v 1.15 2016/12/17 06:17:16 abhinav Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -67,7 +67,7 @@ and
 denoting the quotient and the remainder.
 The type of these correspond with the underlying type of the function.
 .Sh EXAMPLES
-The following example demonstrate the basic usage of the functions.
+The following example demonstrates the basic usage of the functions.
 .Bd -literal -offset indent
 div_t d;
 



CVS commit: src/lib/libc/stdlib

2016-11-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Nov  7 21:52:36 UTC 2016

Modified Files:
src/lib/libc/stdlib: strtod.3

Log Message:
Use the keywords `underflow' and `overflow' in ERANGE summary.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/lib/libc/stdlib/strtod.3

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/stdlib/strtod.3
diff -u src/lib/libc/stdlib/strtod.3:1.28 src/lib/libc/stdlib/strtod.3:1.29
--- src/lib/libc/stdlib/strtod.3:1.28	Mon Nov  7 21:51:42 2016
+++ src/lib/libc/stdlib/strtod.3	Mon Nov  7 21:52:36 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: strtod.3,v 1.28 2016/11/07 21:51:42 riastradh Exp $
+.\"	$NetBSD: strtod.3,v 1.29 2016/11/07 21:52:36 riastradh Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -213,7 +213,7 @@ if (errno) {
 .Sh ERRORS
 .Bl -tag -width Er
 .It Bq Er ERANGE
-The value is too large or small in magnitude to be represented.
+The conversion resulted in floating-point underflow or overflow.
 .El
 .Sh SEE ALSO
 .Xr atof 3 ,



CVS commit: src/lib/libc/stdlib

2016-11-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Nov  7 21:51:42 UTC 2016

Modified Files:
src/lib/libc/stdlib: strtod.3

Log Message:
Fix phrasing about `out-of-band' and `sentinel value'.

Either an out-of-band channel, or an in-band sentinel value, could
indicate an error, but an out-of-band sentinel value is a silly
proposition.

Noted by uwe@.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/lib/libc/stdlib/strtod.3

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/stdlib/strtod.3
diff -u src/lib/libc/stdlib/strtod.3:1.27 src/lib/libc/stdlib/strtod.3:1.28
--- src/lib/libc/stdlib/strtod.3:1.27	Fri Nov  4 20:06:09 2016
+++ src/lib/libc/stdlib/strtod.3	Mon Nov  7 21:51:42 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: strtod.3,v 1.27 2016/11/04 20:06:09 riastradh Exp $
+.\"	$NetBSD: strtod.3,v 1.28 2016/11/07 21:51:42 riastradh Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -171,9 +171,9 @@ the closest subnormal value, or zero, is
 is stored in
 .Va errno .
 .Sh EXAMPLES
-Since there is no out-of-band sentinel value to indicate an error,
-callers who wish to know whether there was overflow or underflow must
-set
+Since there is no out-of-band channel or sentinel value to indicate an
+error, callers who wish to know whether there was overflow or underflow
+must set
 .Va errno
 to zero before calling
 .Fn strtod ,



CVS commit: src/lib/libc/stdlib

2016-11-05 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Nov  5 20:57:31 UTC 2016

Modified Files:
src/lib/libc/stdlib: strtoul.3

Log Message:
Update strtoul(3) example to reflect clarifications in strtol(3).


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/lib/libc/stdlib/strtoul.3

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/stdlib/strtoul.3
diff -u src/lib/libc/stdlib/strtoul.3:1.35 src/lib/libc/stdlib/strtoul.3:1.36
--- src/lib/libc/stdlib/strtoul.3:1.35	Sun May  1 21:28:21 2016
+++ src/lib/libc/stdlib/strtoul.3	Sat Nov  5 20:57:31 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: strtoul.3,v 1.35 2016/05/01 21:28:21 joerg Exp $
+.\"	$NetBSD: strtoul.3,v 1.36 2016/11/05 20:57:31 riastradh Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -227,10 +227,15 @@ unsigned long ulval;
 
 errno = 0;
 ulval = strtoul(buf, \*[Am]ep, 10);
-if (buf[0] == '\e0' || *ep != '\e0')
+if (ep == buf)
 	goto not_a_number;
-if (errno == ERANGE \*[Am]\*[Am] ulval == ULONG_MAX)
+if (*ep != '\e0')
+	goto trailing_garbage;
+if (errno) {
+	assert(errno == ERANGE);
+	assert(ulval == ULONG_MAX);
 	goto out_of_range;
+}
 .Ed
 .Pp
 This example will accept



CVS commit: src/lib/libc/stdlib

2016-11-04 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Nov  4 20:19:58 UTC 2016

Modified Files:
src/lib/libc/stdlib: strtol.3

Log Message:
Bump date for previous.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/lib/libc/stdlib/strtol.3

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/stdlib/strtol.3
diff -u src/lib/libc/stdlib/strtol.3:1.38 src/lib/libc/stdlib/strtol.3:1.39
--- src/lib/libc/stdlib/strtol.3:1.38	Fri Nov  4 20:18:23 2016
+++ src/lib/libc/stdlib/strtol.3	Fri Nov  4 20:19:58 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: strtol.3,v 1.38 2016/11/04 20:18:23 riastradh Exp $
+.\"	$NetBSD: strtol.3,v 1.39 2016/11/04 20:19:58 riastradh Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -33,7 +33,7 @@
 .\"
 .\" from: @(#)strtol.3	8.1 (Berkeley) 6/4/93
 .\"
-.Dd November 13, 2015
+.Dd November 4, 2016
 .Dt STRTOL 3
 .Os
 .Sh NAME



CVS commit: src/lib/libc/stdlib

2016-11-04 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Nov  4 20:18:23 UTC 2016

Modified Files:
src/lib/libc/stdlib: strtol.3

Log Message:
Tidy up the second example too.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/lib/libc/stdlib/strtol.3

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/stdlib/strtol.3
diff -u src/lib/libc/stdlib/strtol.3:1.37 src/lib/libc/stdlib/strtol.3:1.38
--- src/lib/libc/stdlib/strtol.3:1.37	Fri Nov  4 20:16:18 2016
+++ src/lib/libc/stdlib/strtol.3	Fri Nov  4 20:18:23 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: strtol.3,v 1.37 2016/11/04 20:16:18 riastradh Exp $
+.\"	$NetBSD: strtol.3,v 1.38 2016/11/04 20:18:23 riastradh Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -266,11 +266,15 @@ long lval;
 
 errno = 0;
 lval = strtol(buf, \*[Am]ep, 10);
-if (buf[0] == '\e0' || *ep != '\e0')
+if (ep == buf)
 	goto not_a_number;
-if ((errno == ERANGE \*[Am]\*[Am] (lval == LONG_MAX || lval == LONG_MIN)) ||
-(lval \*[Gt] INT_MAX || lval \*[Lt] INT_MIN))
+if (*ep != '\e0')
+	goto trailing_garbage;
+if (errno == ERANGE || lval < INT_MIN || INT_MAX < lval)
 	goto out_of_range;
+assert(errno == 0);
+assert(INT_MIN <= lval);
+assert(lval <= INT_MAX);
 ival = lval;
 .Ed
 .Sh ERRORS



CVS commit: src/lib/libc/stdlib

2016-11-04 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Nov  4 20:16:18 UTC 2016

Modified Files:
src/lib/libc/stdlib: strtol.3

Log Message:
Simplify error condition case.

Add assertions to reflect its implications.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/lib/libc/stdlib/strtol.3

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/stdlib/strtol.3
diff -u src/lib/libc/stdlib/strtol.3:1.36 src/lib/libc/stdlib/strtol.3:1.37
--- src/lib/libc/stdlib/strtol.3:1.36	Fri Nov  4 20:14:31 2016
+++ src/lib/libc/stdlib/strtol.3	Fri Nov  4 20:16:18 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: strtol.3,v 1.36 2016/11/04 20:14:31 riastradh Exp $
+.\"	$NetBSD: strtol.3,v 1.37 2016/11/04 20:16:18 riastradh Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -229,8 +229,11 @@ if (ep == buf)
 	goto not_a_number;
 if (*ep != '\e0')
 	goto trailing_garbage;
-if (errno == ERANGE \*[Am]\*[Am] (lval == LONG_MAX || lval == LONG_MIN))
+if (errno) {
+	assert(errno == ERANGE);
+	assert(lval == LONG_MAX || lval == LONG_MIN);
 	goto out_of_range;
+}
 .Ed
 .Pp
 This example will accept



CVS commit: src/lib/libc/stdlib

2016-11-04 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Nov  4 20:14:31 UTC 2016

Modified Files:
src/lib/libc/stdlib: strtol.3

Log Message:
Distinguish invalid syntax from trailing garbage cases.  Clarify.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/lib/libc/stdlib/strtol.3

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/stdlib/strtol.3
diff -u src/lib/libc/stdlib/strtol.3:1.35 src/lib/libc/stdlib/strtol.3:1.36
--- src/lib/libc/stdlib/strtol.3:1.35	Fri Nov 13 16:00:32 2015
+++ src/lib/libc/stdlib/strtol.3	Fri Nov  4 20:14:31 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: strtol.3,v 1.35 2015/11/13 16:00:32 christos Exp $
+.\"	$NetBSD: strtol.3,v 1.36 2016/11/04 20:14:31 riastradh Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -225,8 +225,10 @@ long lval;
 
 errno = 0;
 lval = strtol(buf, \*[Am]ep, 10);
-if (buf[0] == '\e0' || *ep != '\e0')
+if (ep == buf)
 	goto not_a_number;
+if (*ep != '\e0')
+	goto trailing_garbage;
 if (errno == ERANGE \*[Am]\*[Am] (lval == LONG_MAX || lval == LONG_MIN))
 	goto out_of_range;
 .Ed



CVS commit: src/lib/libc/stdlib

2016-11-04 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Nov  4 20:06:09 UTC 2016

Modified Files:
src/lib/libc/stdlib: strtod.3

Log Message:
Distinguish altogether invalid syntax from trailing garbage.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/lib/libc/stdlib/strtod.3

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/stdlib/strtod.3
diff -u src/lib/libc/stdlib/strtod.3:1.26 src/lib/libc/stdlib/strtod.3:1.27
--- src/lib/libc/stdlib/strtod.3:1.26	Fri Nov  4 20:04:04 2016
+++ src/lib/libc/stdlib/strtod.3	Fri Nov  4 20:06:09 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: strtod.3,v 1.26 2016/11/04 20:04:04 riastradh Exp $
+.\"	$NetBSD: strtod.3,v 1.27 2016/11/04 20:06:09 riastradh Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -198,8 +198,10 @@ double d;
 
 errno = 0;
 d = strtod(s, );
-if (s[0] == '\e0' || end[0] != '\e0')
+if (end == s)
 	errx(EXIT_FAILURE, "invalid syntax");
+if (end[0] != '\e0')
+	errx(EXIT_FAILURE, "trailing garbage");
 if (errno) {
 	assert(errno == ERANGE);
 	assert(isinf(d) || d == 0 ||



CVS commit: src/lib/libc/stdlib

2016-11-04 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Nov  4 20:04:04 UTC 2016

Modified Files:
src/lib/libc/stdlib: strtod.3

Log Message:
EXIT_FAILURE police


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/lib/libc/stdlib/strtod.3

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/stdlib/strtod.3
diff -u src/lib/libc/stdlib/strtod.3:1.25 src/lib/libc/stdlib/strtod.3:1.26
--- src/lib/libc/stdlib/strtod.3:1.25	Fri Nov  4 19:18:53 2016
+++ src/lib/libc/stdlib/strtod.3	Fri Nov  4 20:04:04 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: strtod.3,v 1.25 2016/11/04 19:18:53 riastradh Exp $
+.\"	$NetBSD: strtod.3,v 1.26 2016/11/04 20:04:04 riastradh Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -199,7 +199,7 @@ double d;
 errno = 0;
 d = strtod(s, );
 if (s[0] == '\e0' || end[0] != '\e0')
-	errx(1, "invalid syntax");
+	errx(EXIT_FAILURE, "invalid syntax");
 if (errno) {
 	assert(errno == ERANGE);
 	assert(isinf(d) || d == 0 ||



CVS commit: src/lib/libc/stdlib

2016-11-04 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Nov  4 19:18:53 UTC 2016

Modified Files:
src/lib/libc/stdlib: strtod.3

Log Message:
Fix infinity detection with isinf(d), not d == HUGE_VAL.

Negative infinity counts as overflow too.

Simplify.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/lib/libc/stdlib/strtod.3

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/stdlib/strtod.3
diff -u src/lib/libc/stdlib/strtod.3:1.24 src/lib/libc/stdlib/strtod.3:1.25
--- src/lib/libc/stdlib/strtod.3:1.24	Fri Nov  4 19:10:04 2016
+++ src/lib/libc/stdlib/strtod.3	Fri Nov  4 19:18:53 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: strtod.3,v 1.24 2016/11/04 19:10:04 riastradh Exp $
+.\"	$NetBSD: strtod.3,v 1.25 2016/11/04 19:18:53 riastradh Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -202,9 +202,9 @@ if (s[0] == '\e0' || end[0] != '\e0')
 	errx(1, "invalid syntax");
 if (errno) {
 	assert(errno == ERANGE);
-	assert(d == HUGE_VAL || d == -HUGE_VAL || d == 0 ||
+	assert(isinf(d) || d == 0 ||
 	fpclassify(d) == FP_SUBNORMAL);
-	warnx("%s", d == HUGE_VAL ? "overflow" : "underflow");
+	warnx("%s", isinf(d) ? "overflow" : "underflow");
 }
 /* d is the best floating-point approximation to the number in s */
 .Ed



CVS commit: src/lib/libc/stdlib

2016-11-04 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Nov  4 19:10:05 UTC 2016

Modified Files:
src/lib/libc/stdlib: strtod.3

Log Message:
Add example for strtod.

This illustrates all the cases you might be interested in and asserts
theorems in those cases.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/lib/libc/stdlib/strtod.3

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/stdlib/strtod.3
diff -u src/lib/libc/stdlib/strtod.3:1.23 src/lib/libc/stdlib/strtod.3:1.24
--- src/lib/libc/stdlib/strtod.3:1.23	Fri Nov  4 18:46:15 2016
+++ src/lib/libc/stdlib/strtod.3	Fri Nov  4 19:10:04 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: strtod.3,v 1.23 2016/11/04 18:46:15 riastradh Exp $
+.\"	$NetBSD: strtod.3,v 1.24 2016/11/04 19:10:04 riastradh Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -170,6 +170,44 @@ the closest subnormal value, or zero, is
 .Dv ERANGE
 is stored in
 .Va errno .
+.Sh EXAMPLES
+Since there is no out-of-band sentinel value to indicate an error,
+callers who wish to know whether there was overflow or underflow must
+set
+.Va errno
+to zero before calling
+.Fn strtod ,
+.Fn strtof ,
+or
+.Fn strtold ;
+in the case of no underflow or overflow, these functions preserve
+.Va errno .
+.Pp
+To check for syntax errors, callers must
+.Em also
+check whether
+.Fa endptr
+was updated to reflect the true end of the string in order to determine
+whether the full string was consumed or whether there were additional
+erroneous characters in it.
+.Bd -literal -offset abcd
+char *end;
+double d;
+
+\&...
+
+errno = 0;
+d = strtod(s, );
+if (s[0] == '\e0' || end[0] != '\e0')
+	errx(1, "invalid syntax");
+if (errno) {
+	assert(errno == ERANGE);
+	assert(d == HUGE_VAL || d == -HUGE_VAL || d == 0 ||
+	fpclassify(d) == FP_SUBNORMAL);
+	warnx("%s", d == HUGE_VAL ? "overflow" : "underflow");
+}
+/* d is the best floating-point approximation to the number in s */
+.Ed
 .Sh ERRORS
 .Bl -tag -width Er
 .It Bq Er ERANGE



CVS commit: src/lib/libc/stdlib

2016-11-04 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Nov  4 18:46:15 UTC 2016

Modified Files:
src/lib/libc/stdlib: strtod.3

Log Message:
Fix description of ERANGE cases again.

Do use the technical terms `overflow' and `underflow', because strtod
sets ERANGE precisely to indicate either of these two conditions, and
they are the right keywords that one might be looking for.

Note that strtod may set ERANGE even if it returns noninfinity and
nonzero -- specifically, if the result is subnormal.  This part was
wrong before I `fixed' it and remained wrong after I `fixed' it
earlier this year.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/lib/libc/stdlib/strtod.3

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/stdlib/strtod.3
diff -u src/lib/libc/stdlib/strtod.3:1.22 src/lib/libc/stdlib/strtod.3:1.23
--- src/lib/libc/stdlib/strtod.3:1.22	Thu Mar 17 09:43:38 2016
+++ src/lib/libc/stdlib/strtod.3	Fri Nov  4 18:46:15 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: strtod.3,v 1.22 2016/03/17 09:43:38 wiz Exp $
+.\"	$NetBSD: strtod.3,v 1.23 2016/11/04 18:46:15 riastradh Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -33,7 +33,7 @@
 .\"
 .\" from: @(#)strtod.3	8.1 (Berkeley) 6/4/93
 .\"
-.Dd March 17, 2016
+.Dd November 4, 2016
 .Dt STRTOD 3
 .Os
 .Sh NAME
@@ -151,8 +151,9 @@ If no conversion is performed, zero is r
 is stored in the location referenced by
 .Fa endptr .
 .Pp
-If the correct value is too large in magnitude to be represented, plus
-or minus
+If the correct value is too large in magnitude to be represented
+.Pq Sq overflow ,
+plus or minus
 .Dv HUGE_VAL ,
 .Dv HUGE_VALF ,
 or
@@ -161,8 +162,11 @@ is returned (according to the return typ
 .Dv ERANGE
 is stored in
 .Va errno .
-If the correct value is nonzero but too small in magnitude to be
-represented as nonzero, zero is returned and
+.Pp
+If the correct value is too small in magnitude to be represented
+normally with full precision
+.Pq Sq underflow ,
+the closest subnormal value, or zero, is returned, and
 .Dv ERANGE
 is stored in
 .Va errno .



CVS commit: src/lib/libc/stdlib

2016-06-01 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Wed Jun  1 08:32:05 UTC 2016

Modified Files:
src/lib/libc/stdlib: malloc.3

Log Message:
Fix manually applied patch. Mark up NULL with Dv.


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/lib/libc/stdlib/malloc.3

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/stdlib/malloc.3
diff -u src/lib/libc/stdlib/malloc.3:1.47 src/lib/libc/stdlib/malloc.3:1.48
--- src/lib/libc/stdlib/malloc.3:1.47	Wed Jun  1 05:40:26 2016
+++ src/lib/libc/stdlib/malloc.3	Wed Jun  1 08:32:05 2016
@@ -1,4 +1,4 @@
-.\" $NetBSD: malloc.3,v 1.47 2016/06/01 05:40:26 pgoyette Exp $
+.\" $NetBSD: malloc.3,v 1.48 2016/06/01 08:32:05 wiz Exp $
 .\"
 .\" Copyright (c) 1980, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -144,11 +144,13 @@ The
 .Fn realloc
 function always leaves the original buffer intact
 when an error occurs.
-+If
-+.Ar size
-+is 0, either NULL or a pointer that can be safely passed to
-+.Xr free 3
-+is returned.
+If
+.Ar size
+is 0, either
+.Dv NULL
+or a pointer that can be safely passed to
+.Xr free 3
+is returned.
 .Pp
 The
 .Fn free



CVS commit: src/lib/libc/stdlib

2016-05-31 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Wed Jun  1 05:40:27 UTC 2016

Modified Files:
src/lib/libc/stdlib: malloc.3

Log Message:
Document return value for realloc(3) when size is 0.  From PR lib/47384


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/lib/libc/stdlib/malloc.3

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/stdlib/malloc.3
diff -u src/lib/libc/stdlib/malloc.3:1.46 src/lib/libc/stdlib/malloc.3:1.47
--- src/lib/libc/stdlib/malloc.3:1.46	Sat Nov  7 18:46:37 2015
+++ src/lib/libc/stdlib/malloc.3	Wed Jun  1 05:40:26 2016
@@ -1,4 +1,4 @@
-.\" $NetBSD: malloc.3,v 1.46 2015/11/07 18:46:37 wiz Exp $
+.\" $NetBSD: malloc.3,v 1.47 2016/06/01 05:40:26 pgoyette Exp $
 .\"
 .\" Copyright (c) 1980, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -34,7 +34,7 @@
 .\" @(#)malloc.3	8.1 (Berkeley) 6/4/93
 .\" $FreeBSD: src/lib/libc/stdlib/malloc.3,v 1.73 2007/06/15 22:32:33 jasone Exp $
 .\"
-.Dd July 26, 2015
+.Dd June 1, 2016
 .Dt MALLOC 3
 .Os
 .Sh NAME
@@ -144,6 +144,11 @@ The
 .Fn realloc
 function always leaves the original buffer intact
 when an error occurs.
++If
++.Ar size
++is 0, either NULL or a pointer that can be safely passed to
++.Xr free 3
++is returned.
 .Pp
 The
 .Fn free



CVS commit: src/lib/libc/stdlib

2016-05-01 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sun May  1 21:28:21 UTC 2016

Modified Files:
src/lib/libc/stdlib: strtoul.3

Log Message:
Fix type name. From Abhinav.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/lib/libc/stdlib/strtoul.3

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/stdlib/strtoul.3
diff -u src/lib/libc/stdlib/strtoul.3:1.34 src/lib/libc/stdlib/strtoul.3:1.35
--- src/lib/libc/stdlib/strtoul.3:1.34	Fri Nov 13 16:00:32 2015
+++ src/lib/libc/stdlib/strtoul.3	Sun May  1 21:28:21 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: strtoul.3,v 1.34 2015/11/13 16:00:32 christos Exp $
+.\"	$NetBSD: strtoul.3,v 1.35 2016/05/01 21:28:21 joerg Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -41,7 +41,7 @@
 .Nm strtoull ,
 .Nm strtoumax ,
 .Nm strtouq
-.Nd convert a string to an unsigned long, unsigned long long, uintmax_t or uquad_t integer
+.Nd convert a string to an unsigned long, unsigned long long, uintmax_t or u_quad_t integer
 .Sh LIBRARY
 .Lb libc
 .Sh SYNOPSIS



CVS commit: src/lib/libc/stdlib

2016-04-12 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Tue Apr 12 18:07:09 UTC 2016

Modified Files:
src/lib/libc/stdlib: jemalloc.c

Log Message:
lib/50791: Instead of using sorting the arena chunks by address only,
sort by size of the longest run and address as tie break. Avoids long
linear searches for code heavy on medium sized allocations.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/lib/libc/stdlib/jemalloc.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/stdlib/jemalloc.c
diff -u src/lib/libc/stdlib/jemalloc.c:1.39 src/lib/libc/stdlib/jemalloc.c:1.40
--- src/lib/libc/stdlib/jemalloc.c:1.39	Sun Jan 24 21:56:43 2016
+++ src/lib/libc/stdlib/jemalloc.c	Tue Apr 12 18:07:08 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: jemalloc.c,v 1.39 2016/01/24 21:56:43 christos Exp $	*/
+/*	$NetBSD: jemalloc.c,v 1.40 2016/04/12 18:07:08 joerg Exp $	*/
 
 /*-
  * Copyright (C) 2006,2007 Jason Evans .
@@ -118,7 +118,7 @@
 
 #include 
 /* __FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.147 2007/06/15 22:00:16 jasone Exp $"); */ 
-__RCSID("$NetBSD: jemalloc.c,v 1.39 2016/01/24 21:56:43 christos Exp $");
+__RCSID("$NetBSD: jemalloc.c,v 1.40 2016/04/12 18:07:08 joerg Exp $");
 
 #ifdef __FreeBSD__
 #include "libc_private.h"
@@ -1661,6 +1661,11 @@ arena_chunk_comp(arena_chunk_t *a, arena
 	assert(a != NULL);
 	assert(b != NULL);
 
+	if (a->max_frun_npages < b->max_frun_npages)
+		return -1;
+	if (a->max_frun_npages > b->max_frun_npages)
+		return 1;
+
 	if ((uintptr_t)a < (uintptr_t)b)
 		return (-1);
 	else if (a == b)
@@ -1912,9 +1917,6 @@ arena_chunk_alloc(arena_t *arena)
 
 		chunk->arena = arena;
 
-		/* LINTED */
-		RB_INSERT(arena_chunk_tree_s, >chunks, chunk);
-
 		/*
 		 * Claim that no pages are in use, since the header is merely
 		 * overhead.
@@ -1934,6 +1936,8 @@ arena_chunk_alloc(arena_t *arena)
 		chunk->map[chunk_npages - 1].npages = chunk_npages -
 		arena_chunk_header_npages;
 		chunk->map[chunk_npages - 1].pos = POS_FREE;
+
+		RB_INSERT(arena_chunk_tree_s, >chunks, chunk);
 	}
 
 	return (chunk);
@@ -1970,30 +1974,44 @@ arena_chunk_dealloc(arena_t *arena, aren
 static arena_run_t *
 arena_run_alloc(arena_t *arena, size_t size)
 {
-	arena_chunk_t *chunk;
+	arena_chunk_t *chunk, *chunk_tmp;
 	arena_run_t *run;
-	unsigned need_npages, limit_pages, compl_need_npages;
+	unsigned need_npages;
 
 	assert(size <= (chunksize - (arena_chunk_header_npages <<
 	pagesize_2pow)));
 	assert((size & pagesize_mask) == 0);
 
 	/*
-	 * Search through arena's chunks in address order for a free run that is
-	 * large enough.  Look for the first fit.
+	 * Search through the arena chunk tree for a large enough free run.
+	 * Tree order ensures that any exact fit is picked immediately or
+	 * otherwise the lowest address of the next size.
 	 */
 	need_npages = (unsigned)(size >> pagesize_2pow);
-	limit_pages = chunk_npages - arena_chunk_header_npages;
-	compl_need_npages = limit_pages - need_npages;
 	/* LINTED */
-	RB_FOREACH(chunk, arena_chunk_tree_s, >chunks) {
+	for (;;) {
+		chunk_tmp = RB_ROOT(>chunks);
+		chunk = NULL;
+		while (chunk_tmp) {
+			if (chunk_tmp->max_frun_npages == need_npages) {
+chunk = chunk_tmp;
+break;
+			}
+			if (chunk_tmp->max_frun_npages < need_npages) {
+chunk_tmp = RB_RIGHT(chunk_tmp, link);
+continue;
+			}
+			chunk = chunk_tmp;
+			chunk_tmp = RB_LEFT(chunk, link);
+		}
+		if (chunk == NULL)
+			break;
 		/*
-		 * Avoid searching this chunk if there are not enough
-		 * contiguous free pages for there to possibly be a large
-		 * enough free run.
+		 * At this point, the chunk must have a cached run size large
+		 * enough to fit the allocation.
 		 */
-		if (chunk->pages_used <= compl_need_npages &&
-		need_npages <= chunk->max_frun_npages) {
+		assert(need_npages <= chunk->max_frun_npages);
+		{
 			arena_chunk_map_t *mapelm;
 			unsigned i;
 			unsigned max_frun_npages = 0;
@@ -2031,7 +2049,9 @@ arena_run_alloc(arena_t *arena, size_t s
 			 * chunk->min_frun_ind was already reset above (if
 			 * necessary).
 			 */
+			RB_REMOVE(arena_chunk_tree_s, >chunks, chunk);
 			chunk->max_frun_npages = max_frun_npages;
+			RB_INSERT(arena_chunk_tree_s, >chunks, chunk);
 		}
 	}
 
@@ -2114,8 +2134,11 @@ arena_run_dalloc(arena_t *arena, arena_r
 		assert(chunk->map[run_ind + run_pages - 1].pos == POS_FREE);
 	}
 
-	if (chunk->map[run_ind].npages > chunk->max_frun_npages)
+	if (chunk->map[run_ind].npages > chunk->max_frun_npages) {
+		RB_REMOVE(arena_chunk_tree_s, >chunks, chunk);
 		chunk->max_frun_npages = chunk->map[run_ind].npages;
+		RB_INSERT(arena_chunk_tree_s, >chunks, chunk);
+	}
 	if (run_ind < chunk->min_frun_ind)
 		chunk->min_frun_ind = run_ind;
 



CVS commit: src/lib/libc/stdlib

2016-04-06 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Wed Apr  6 11:07:58 UTC 2016

Modified Files:
src/lib/libc/stdlib: reallocarray.c

Log Message:
Revert prior, no idea why it was causing me problems, but it no longer does.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/libc/stdlib/reallocarray.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/stdlib/reallocarray.c
diff -u src/lib/libc/stdlib/reallocarray.c:1.6 src/lib/libc/stdlib/reallocarray.c:1.7
--- src/lib/libc/stdlib/reallocarray.c:1.6	Tue Apr  5 15:01:26 2016
+++ src/lib/libc/stdlib/reallocarray.c	Wed Apr  6 11:07:58 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: reallocarray.c,v 1.6 2016/04/05 15:01:26 roy Exp $	*/
+/*	$NetBSD: reallocarray.c,v 1.7 2016/04/06 11:07:58 roy Exp $	*/
 /*	$OpenBSD: reallocarray.c,v 1.1 2014/05/08 21:43:49 deraadt Exp $	*/
 
 /*-
@@ -31,29 +31,23 @@
  */
 
 #include 
-__RCSID("$NetBSD: reallocarray.c,v 1.6 2016/04/05 15:01:26 roy Exp $");
+__RCSID("$NetBSD: reallocarray.c,v 1.7 2016/04/06 11:07:58 roy Exp $");
 
 #define _OPENBSD_SOURCE
 #include 
-#include 
 #include 
 
-#define SQRT_SIZE_MAX (((size_t)1) << (sizeof(size_t) * CHAR_BIT / 2))
 void *
 reallocarray(void *optr, size_t nmemb, size_t size)
 {
+	int e;
 
-	/*
-	 * Try to avoid division here.
-	 *
-	 * It isn't possible to overflow during multiplication if neither
-	 * operand uses any of the most significant half of the bits.
-	 */
-	if (__predict_false((nmemb | size) >= SQRT_SIZE_MAX &&
-			nmemb > SIZE_MAX / size))
-	{
-		errno = EOVERFLOW;
-		return NULL;
-	}
-	return realloc(optr, nmemb * size);
+	if (nmemb == 0 || size == 0)
+		return realloc(optr, 0);
+
+	e = reallocarr(, nmemb, size);
+	if (e == 0)
+		return optr;
+	errno = e;
+	return NULL;
 }



CVS commit: src/lib/libc/stdlib

2016-04-05 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Tue Apr  5 15:01:26 UTC 2016

Modified Files:
src/lib/libc/stdlib: reallocarray.c

Log Message:
Stop calling reallocarr and just do the same bounds checking but without
messing around with copying pointers which was causing ssh to crash.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libc/stdlib/reallocarray.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/stdlib/reallocarray.c
diff -u src/lib/libc/stdlib/reallocarray.c:1.5 src/lib/libc/stdlib/reallocarray.c:1.6
--- src/lib/libc/stdlib/reallocarray.c:1.5	Sun Jul 26 02:22:33 2015
+++ src/lib/libc/stdlib/reallocarray.c	Tue Apr  5 15:01:26 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: reallocarray.c,v 1.5 2015/07/26 02:22:33 kamil Exp $	*/
+/*	$NetBSD: reallocarray.c,v 1.6 2016/04/05 15:01:26 roy Exp $	*/
 /*	$OpenBSD: reallocarray.c,v 1.1 2014/05/08 21:43:49 deraadt Exp $	*/
 
 /*-
@@ -31,22 +31,29 @@
  */
 
 #include 
-__RCSID("$NetBSD: reallocarray.c,v 1.5 2015/07/26 02:22:33 kamil Exp $");
+__RCSID("$NetBSD: reallocarray.c,v 1.6 2016/04/05 15:01:26 roy Exp $");
 
 #define _OPENBSD_SOURCE
 #include 
+#include 
 #include 
 
+#define SQRT_SIZE_MAX (((size_t)1) << (sizeof(size_t) * CHAR_BIT / 2))
 void *
 reallocarray(void *optr, size_t nmemb, size_t size)
 {
-	if (nmemb == 0 || size == 0)
-		return realloc(optr, 0);
 
-	int e = reallocarr(, nmemb, size);
-
-	if (e == 0)
-		return optr;
-	errno = e;
-	return NULL;
+	/*
+	 * Try to avoid division here.
+	 *
+	 * It isn't possible to overflow during multiplication if neither
+	 * operand uses any of the most significant half of the bits.
+	 */
+	if (__predict_false((nmemb | size) >= SQRT_SIZE_MAX &&
+			nmemb > SIZE_MAX / size))
+	{
+		errno = EOVERFLOW;
+		return NULL;
+	}
+	return realloc(optr, nmemb * size);
 }



CVS commit: src/lib/libc/stdlib

2016-03-19 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Thu Mar 17 09:43:38 UTC 2016

Modified Files:
src/lib/libc/stdlib: strtod.3

Log Message:
Bump date for previous.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/lib/libc/stdlib/strtod.3

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/stdlib/strtod.3
diff -u src/lib/libc/stdlib/strtod.3:1.21 src/lib/libc/stdlib/strtod.3:1.22
--- src/lib/libc/stdlib/strtod.3:1.21	Thu Mar 17 03:26:15 2016
+++ src/lib/libc/stdlib/strtod.3	Thu Mar 17 09:43:38 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: strtod.3,v 1.21 2016/03/17 03:26:15 riastradh Exp $
+.\"	$NetBSD: strtod.3,v 1.22 2016/03/17 09:43:38 wiz Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -33,7 +33,7 @@
 .\"
 .\" from: @(#)strtod.3	8.1 (Berkeley) 6/4/93
 .\"
-.Dd March 12, 2006
+.Dd March 17, 2016
 .Dt STRTOD 3
 .Os
 .Sh NAME



CVS commit: src/lib/libc/stdlib

2016-03-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Mar 17 03:26:15 UTC 2016

Modified Files:
src/lib/libc/stdlib: strtod.3

Log Message:
strtod yields ERANGE for below-subnormal magnitudes, not underflow.

For a floating-point computation, in the language of IEEE 754,
`underflow' means the output was rounded and is too small to be
represented *normally*.

There are many nonzero floating-point numbers to which the exact
output may have been rounded -- namely subnormals.  The condition
under which strtod returns ERANGE for small magnitudes is when the
magnitude of the exact result is so small it is rounded to zero, not
even to a subnormal.

While here, use parallel language about large magnitudes instead of
the (albeit correct) word `overflow', to avoid temptation to treat
`underflow' as the opposite notion with zero instead of infinity.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/lib/libc/stdlib/strtod.3

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/stdlib/strtod.3
diff -u src/lib/libc/stdlib/strtod.3:1.20 src/lib/libc/stdlib/strtod.3:1.21
--- src/lib/libc/stdlib/strtod.3:1.20	Wed Oct 24 13:42:10 2007
+++ src/lib/libc/stdlib/strtod.3	Thu Mar 17 03:26:15 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: strtod.3,v 1.20 2007/10/24 13:42:10 reed Exp $
+.\"	$NetBSD: strtod.3,v 1.21 2016/03/17 03:26:15 riastradh Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -151,7 +151,8 @@ If no conversion is performed, zero is r
 is stored in the location referenced by
 .Fa endptr .
 .Pp
-If the correct value would cause overflow, plus or minus
+If the correct value is too large in magnitude to be represented, plus
+or minus
 .Dv HUGE_VAL ,
 .Dv HUGE_VALF ,
 or
@@ -160,15 +161,15 @@ is returned (according to the return typ
 .Dv ERANGE
 is stored in
 .Va errno .
-If the correct value would cause underflow, zero is
-returned and
+If the correct value is nonzero but too small in magnitude to be
+represented as nonzero, zero is returned and
 .Dv ERANGE
 is stored in
 .Va errno .
 .Sh ERRORS
 .Bl -tag -width Er
 .It Bq Er ERANGE
-Overflow or underflow occurred.
+The value is too large or small in magnitude to be represented.
 .El
 .Sh SEE ALSO
 .Xr atof 3 ,



CVS commit: src/lib/libc/stdlib

2016-01-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Jan 20 15:31:55 UTC 2016

Modified Files:
src/lib/libc/stdlib: tdelete.c

Log Message:
PR/50681: Markiyan Kushnir: Fix memory leak when we delete the root node.
It is questionable if we should return NULL in that case, but what is the
parent of root? The new adjusted root?


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/libc/stdlib/tdelete.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/stdlib/tdelete.c
diff -u src/lib/libc/stdlib/tdelete.c:1.6 src/lib/libc/stdlib/tdelete.c:1.7
--- src/lib/libc/stdlib/tdelete.c:1.6	Mon Jun 25 18:32:45 2012
+++ src/lib/libc/stdlib/tdelete.c	Wed Jan 20 10:31:55 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: tdelete.c,v 1.6 2012/06/25 22:32:45 abs Exp $	*/
+/*	$NetBSD: tdelete.c,v 1.7 2016/01/20 15:31:55 christos Exp $	*/
 
 /*
  * Tree search generalized from Knuth (6.2.2) Algorithm T just like
@@ -13,7 +13,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: tdelete.c,v 1.6 2012/06/25 22:32:45 abs Exp $");
+__RCSID("$NetBSD: tdelete.c,v 1.7 2016/01/20 15:31:55 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include 
@@ -60,8 +60,9 @@ tdelete(const void *vkey, void **vrootp,
 			q->rlink = (*rootp)->rlink;
 		}
 	}
-	if (p != *rootp)
-		free(*rootp);			/* D4: Free node */
+	if (p == *rootp)
+		p = NULL;
+	free(*rootp);/* D4: Free node */
 	*rootp = q;/* link parent to new node */
 	return p;
 }



CVS commit: src/lib/libc/stdlib

2016-01-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Jan 20 20:47:41 UTC 2016

Modified Files:
src/lib/libc/stdlib: tdelete.c

Log Message:
Don't return NULL when we are freeing the root node; return a free'd pointer
instead.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/lib/libc/stdlib/tdelete.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/stdlib/tdelete.c
diff -u src/lib/libc/stdlib/tdelete.c:1.7 src/lib/libc/stdlib/tdelete.c:1.8
--- src/lib/libc/stdlib/tdelete.c:1.7	Wed Jan 20 10:31:55 2016
+++ src/lib/libc/stdlib/tdelete.c	Wed Jan 20 15:47:41 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: tdelete.c,v 1.7 2016/01/20 15:31:55 christos Exp $	*/
+/*	$NetBSD: tdelete.c,v 1.8 2016/01/20 20:47:41 christos Exp $	*/
 
 /*
  * Tree search generalized from Knuth (6.2.2) Algorithm T just like
@@ -13,7 +13,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: tdelete.c,v 1.7 2016/01/20 15:31:55 christos Exp $");
+__RCSID("$NetBSD: tdelete.c,v 1.8 2016/01/20 20:47:41 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include 
@@ -60,8 +60,6 @@ tdelete(const void *vkey, void **vrootp,
 			q->rlink = (*rootp)->rlink;
 		}
 	}
-	if (p == *rootp)
-		p = NULL;
 	free(*rootp);/* D4: Free node */
 	*rootp = q;/* link parent to new node */
 	return p;



CVS commit: src/lib/libc/stdlib

2015-11-13 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Fri Nov 13 09:50:31 UTC 2015

Modified Files:
src/lib/libc/stdlib: strtoi.3 strtol.3 strtou.3 strtoul.3

Log Message:
Remove trailing whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libc/stdlib/strtoi.3 \
src/lib/libc/stdlib/strtou.3
cvs rdiff -u -r1.33 -r1.34 src/lib/libc/stdlib/strtol.3
cvs rdiff -u -r1.32 -r1.33 src/lib/libc/stdlib/strtoul.3

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/stdlib/strtoi.3
diff -u src/lib/libc/stdlib/strtoi.3:1.4 src/lib/libc/stdlib/strtoi.3:1.5
--- src/lib/libc/stdlib/strtoi.3:1.4	Thu Nov 12 17:30:03 2015
+++ src/lib/libc/stdlib/strtoi.3	Fri Nov 13 09:50:31 2015
@@ -1,4 +1,4 @@
-.\"	$NetBSD: strtoi.3,v 1.4 2015/11/12 17:30:03 christos Exp $
+.\"	$NetBSD: strtoi.3,v 1.5 2015/11/13 09:50:31 wiz Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -102,7 +102,7 @@ or
 .Ql 0X
 prefix,
 and the number will be read in base 16; otherwise,
-if the 
+if the
 .Fa base
 is zero or 2,
 the string may then include a
Index: src/lib/libc/stdlib/strtou.3
diff -u src/lib/libc/stdlib/strtou.3:1.4 src/lib/libc/stdlib/strtou.3:1.5
--- src/lib/libc/stdlib/strtou.3:1.4	Thu Nov 12 17:30:03 2015
+++ src/lib/libc/stdlib/strtou.3	Fri Nov 13 09:50:31 2015
@@ -1,4 +1,4 @@
-.\"	$NetBSD: strtou.3,v 1.4 2015/11/12 17:30:03 christos Exp $
+.\"	$NetBSD: strtou.3,v 1.5 2015/11/13 09:50:31 wiz Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -102,7 +102,7 @@ or
 prefix,
 and the number will be read in base 16; otherwise,
 and the number will be read in base 16; otherwise,
-if the 
+if the
 .Fa base
 is zero or 2,
 the string may then include a

Index: src/lib/libc/stdlib/strtol.3
diff -u src/lib/libc/stdlib/strtol.3:1.33 src/lib/libc/stdlib/strtol.3:1.34
--- src/lib/libc/stdlib/strtol.3:1.33	Thu Nov 12 17:30:03 2015
+++ src/lib/libc/stdlib/strtol.3	Fri Nov 13 09:50:31 2015
@@ -1,4 +1,4 @@
-.\"	$NetBSD: strtol.3,v 1.33 2015/11/12 17:30:03 christos Exp $
+.\"	$NetBSD: strtol.3,v 1.34 2015/11/13 09:50:31 wiz Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -117,7 +117,7 @@ or
 .Ql 0X
 prefix,
 and the number will be read in base 16; otherwise,
-if the 
+if the
 .Fa base
 is zero or 2,
 the string may then include a

Index: src/lib/libc/stdlib/strtoul.3
diff -u src/lib/libc/stdlib/strtoul.3:1.32 src/lib/libc/stdlib/strtoul.3:1.33
--- src/lib/libc/stdlib/strtoul.3:1.32	Thu Nov 12 17:30:03 2015
+++ src/lib/libc/stdlib/strtoul.3	Fri Nov 13 09:50:31 2015
@@ -1,4 +1,4 @@
-.\"	$NetBSD: strtoul.3,v 1.32 2015/11/12 17:30:03 christos Exp $
+.\"	$NetBSD: strtoul.3,v 1.33 2015/11/13 09:50:31 wiz Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -118,7 +118,7 @@ or
 prefix,
 and the number will be read in base 16; otherwise,
 and the number will be read in base 16; otherwise,
-if the 
+if the
 .Fa base
 is zero or 2,
 the string may then include a



CVS commit: src/lib/libc/stdlib

2015-11-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Nov 13 16:00:32 UTC 2015

Modified Files:
src/lib/libc/stdlib: strtoi.3 strtol.3 strtou.3 strtoul.3

Log Message:
revert 0b documentation.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libc/stdlib/strtoi.3 \
src/lib/libc/stdlib/strtou.3
cvs rdiff -u -r1.34 -r1.35 src/lib/libc/stdlib/strtol.3
cvs rdiff -u -r1.33 -r1.34 src/lib/libc/stdlib/strtoul.3

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/stdlib/strtoi.3
diff -u src/lib/libc/stdlib/strtoi.3:1.5 src/lib/libc/stdlib/strtoi.3:1.6
--- src/lib/libc/stdlib/strtoi.3:1.5	Fri Nov 13 04:50:31 2015
+++ src/lib/libc/stdlib/strtoi.3	Fri Nov 13 11:00:32 2015
@@ -1,4 +1,4 @@
-.\"	$NetBSD: strtoi.3,v 1.5 2015/11/13 09:50:31 wiz Exp $
+.\"	$NetBSD: strtoi.3,v 1.6 2015/11/13 16:00:32 christos Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -36,7 +36,7 @@
 .\" Created by Kamil Rytarowski, based on ID:
 .\" NetBSD: strtol.3,v 1.31 2015/03/11 09:57:35 wiz Exp
 .\"
-.Dd November 12, 2015
+.Dd November 13, 2015
 .Dt STRTOI 3
 .Os
 .Sh NAME
@@ -102,15 +102,15 @@ or
 .Ql 0X
 prefix,
 and the number will be read in base 16; otherwise,
-if the
-.Fa base
-is zero or 2,
-the string may then include a
-.Ql 0b
-or
-.Ql 0B
-prefix,
-and the number will be read in base 2; otherwise,
+.\" if the
+.\" .Fa base
+.\" is zero or 2,
+.\" the string may then include a
+.\" .Ql 0b
+.\" or
+.\" .Ql 0B
+.\" prefix,
+.\" and the number will be read in base 2; otherwise,
 a zero
 .Fa base
 is taken as 10 (decimal) unless the next character is
Index: src/lib/libc/stdlib/strtou.3
diff -u src/lib/libc/stdlib/strtou.3:1.5 src/lib/libc/stdlib/strtou.3:1.6
--- src/lib/libc/stdlib/strtou.3:1.5	Fri Nov 13 04:50:31 2015
+++ src/lib/libc/stdlib/strtou.3	Fri Nov 13 11:00:32 2015
@@ -1,4 +1,4 @@
-.\"	$NetBSD: strtou.3,v 1.5 2015/11/13 09:50:31 wiz Exp $
+.\"	$NetBSD: strtou.3,v 1.6 2015/11/13 16:00:32 christos Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -36,7 +36,7 @@
 .\" Created by Kamil Rytarowski, based on ID:
 .\" NetBSD: strtoul.3,v 1.29 2015/03/10 13:00:58 christos Exp
 .\"
-.Dd November 15, 2015
+.Dd November 13, 2015
 .Dt STRTOU 3
 .Os
 .Sh NAME
@@ -101,16 +101,15 @@ or
 .Ql 0X
 prefix,
 and the number will be read in base 16; otherwise,
-and the number will be read in base 16; otherwise,
-if the
-.Fa base
-is zero or 2,
-the string may then include a
-.Ql 0b
-or
-.Ql 0B
-prefix,
-and the number will be read in base 2; otherwise,
+.\" if the
+.\" .Fa base
+.\" is zero or 2,
+.\" the string may then include a
+.\" .Ql 0b
+.\" or
+.\" .Ql 0B
+.\" prefix,
+.\" and the number will be read in base 2; otherwise,
 a zero
 .Fa base
 is taken as 10 (decimal) unless the next character is

Index: src/lib/libc/stdlib/strtol.3
diff -u src/lib/libc/stdlib/strtol.3:1.34 src/lib/libc/stdlib/strtol.3:1.35
--- src/lib/libc/stdlib/strtol.3:1.34	Fri Nov 13 04:50:31 2015
+++ src/lib/libc/stdlib/strtol.3	Fri Nov 13 11:00:32 2015
@@ -1,4 +1,4 @@
-.\"	$NetBSD: strtol.3,v 1.34 2015/11/13 09:50:31 wiz Exp $
+.\"	$NetBSD: strtol.3,v 1.35 2015/11/13 16:00:32 christos Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -33,7 +33,7 @@
 .\"
 .\" from: @(#)strtol.3	8.1 (Berkeley) 6/4/93
 .\"
-.Dd November 15, 2015
+.Dd November 13, 2015
 .Dt STRTOL 3
 .Os
 .Sh NAME
@@ -117,15 +117,15 @@ or
 .Ql 0X
 prefix,
 and the number will be read in base 16; otherwise,
-if the
-.Fa base
-is zero or 2,
-the string may then include a
-.Ql 0b
-or
-.Ql 0B
-prefix,
-and the number will be read in base 2; otherwise,
+.\" if the
+.\" .Fa base
+.\" is zero or 2,
+.\" the string may then include a
+.\" .Ql 0b
+.\" or
+.\" .Ql 0B
+.\" prefix,
+.\" and the number will be read in base 2; otherwise,
 a zero
 .Fa base
 is taken as 10 (decimal) unless the next character is

Index: src/lib/libc/stdlib/strtoul.3
diff -u src/lib/libc/stdlib/strtoul.3:1.33 src/lib/libc/stdlib/strtoul.3:1.34
--- src/lib/libc/stdlib/strtoul.3:1.33	Fri Nov 13 04:50:31 2015
+++ src/lib/libc/stdlib/strtoul.3	Fri Nov 13 11:00:32 2015
@@ -1,4 +1,4 @@
-.\"	$NetBSD: strtoul.3,v 1.33 2015/11/13 09:50:31 wiz Exp $
+.\"	$NetBSD: strtoul.3,v 1.34 2015/11/13 16:00:32 christos Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -33,7 +33,7 @@
 .\"
 .\" from: @(#)strtoul.3	8.1 (Berkeley) 6/4/93
 .\"
-.Dd November 15, 2015
+.Dd November 13, 2015
 .Dt STRTOUL 3
 .Os
 .Sh NAME
@@ -117,16 +117,15 @@ or
 .Ql 0X
 prefix,
 and the number will be read in base 16; otherwise,
-and the number will be read in base 16; otherwise,
-if the
-.Fa base
-is zero or 2,
-the string may then include a
-.Ql 0b
-or
-.Ql 

CVS commit: src/lib/libc/stdlib

2015-11-12 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Nov 12 17:30:03 UTC 2015

Modified Files:
src/lib/libc/stdlib: strtoi.3 strtol.3 strtou.3 strtoul.3

Log Message:
Now that our source tree has binary constants, recognize them.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/stdlib/strtoi.3 \
src/lib/libc/stdlib/strtou.3
cvs rdiff -u -r1.32 -r1.33 src/lib/libc/stdlib/strtol.3
cvs rdiff -u -r1.31 -r1.32 src/lib/libc/stdlib/strtoul.3

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/stdlib/strtoi.3
diff -u src/lib/libc/stdlib/strtoi.3:1.3 src/lib/libc/stdlib/strtoi.3:1.4
--- src/lib/libc/stdlib/strtoi.3:1.3	Sat Jul 11 11:50:56 2015
+++ src/lib/libc/stdlib/strtoi.3	Thu Nov 12 12:30:03 2015
@@ -1,4 +1,4 @@
-.\"	$NetBSD: strtoi.3,v 1.3 2015/07/11 15:50:56 wiz Exp $
+.\"	$NetBSD: strtoi.3,v 1.4 2015/11/12 17:30:03 christos Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -36,7 +36,7 @@
 .\" Created by Kamil Rytarowski, based on ID:
 .\" NetBSD: strtol.3,v 1.31 2015/03/11 09:57:35 wiz Exp
 .\"
-.Dd April 30, 2015
+.Dd November 12, 2015
 .Dt STRTOI 3
 .Os
 .Sh NAME
@@ -98,8 +98,20 @@ If
 is zero or 16,
 the string may then include a
 .Ql 0x
+or
+.Ql 0X
+prefix,
+and the number will be read in base 16; otherwise,
+if the 
+.Fa base
+is zero or 2,
+the string may then include a
+.Ql 0b
+or
+.Ql 0B
 prefix,
-and the number will be read in base 16; otherwise, a zero
+and the number will be read in base 2; otherwise,
+a zero
 .Fa base
 is taken as 10 (decimal) unless the next character is
 .Ql 0 ,
Index: src/lib/libc/stdlib/strtou.3
diff -u src/lib/libc/stdlib/strtou.3:1.3 src/lib/libc/stdlib/strtou.3:1.4
--- src/lib/libc/stdlib/strtou.3:1.3	Sat Jul 11 11:51:33 2015
+++ src/lib/libc/stdlib/strtou.3	Thu Nov 12 12:30:03 2015
@@ -1,4 +1,4 @@
-.\"	$NetBSD: strtou.3,v 1.3 2015/07/11 15:51:33 wiz Exp $
+.\"	$NetBSD: strtou.3,v 1.4 2015/11/12 17:30:03 christos Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -36,7 +36,7 @@
 .\" Created by Kamil Rytarowski, based on ID:
 .\" NetBSD: strtoul.3,v 1.29 2015/03/10 13:00:58 christos Exp
 .\"
-.Dd April 30, 2015
+.Dd November 15, 2015
 .Dt STRTOU 3
 .Os
 .Sh NAME
@@ -97,8 +97,21 @@ If
 is zero or 16,
 the string may then include a
 .Ql 0x
+or
+.Ql 0X
+prefix,
+and the number will be read in base 16; otherwise,
+and the number will be read in base 16; otherwise,
+if the 
+.Fa base
+is zero or 2,
+the string may then include a
+.Ql 0b
+or
+.Ql 0B
 prefix,
-and the number will be read in base 16; otherwise, a zero
+and the number will be read in base 2; otherwise,
+a zero
 .Fa base
 is taken as 10 (decimal) unless the next character is
 .Ql 0 ,

Index: src/lib/libc/stdlib/strtol.3
diff -u src/lib/libc/stdlib/strtol.3:1.32 src/lib/libc/stdlib/strtol.3:1.33
--- src/lib/libc/stdlib/strtol.3:1.32	Fri May  1 10:17:56 2015
+++ src/lib/libc/stdlib/strtol.3	Thu Nov 12 12:30:03 2015
@@ -1,4 +1,4 @@
-.\"	$NetBSD: strtol.3,v 1.32 2015/05/01 14:17:56 christos Exp $
+.\"	$NetBSD: strtol.3,v 1.33 2015/11/12 17:30:03 christos Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -33,7 +33,7 @@
 .\"
 .\" from: @(#)strtol.3	8.1 (Berkeley) 6/4/93
 .\"
-.Dd April 30, 2015
+.Dd November 15, 2015
 .Dt STRTOL 3
 .Os
 .Sh NAME
@@ -113,8 +113,20 @@ If
 is zero or 16,
 the string may then include a
 .Ql 0x
+or
+.Ql 0X
+prefix,
+and the number will be read in base 16; otherwise,
+if the 
+.Fa base
+is zero or 2,
+the string may then include a
+.Ql 0b
+or
+.Ql 0B
 prefix,
-and the number will be read in base 16; otherwise, a zero
+and the number will be read in base 2; otherwise,
+a zero
 .Fa base
 is taken as 10 (decimal) unless the next character is
 .Ql 0 ,

Index: src/lib/libc/stdlib/strtoul.3
diff -u src/lib/libc/stdlib/strtoul.3:1.31 src/lib/libc/stdlib/strtoul.3:1.32
--- src/lib/libc/stdlib/strtoul.3:1.31	Sun May  3 08:29:28 2015
+++ src/lib/libc/stdlib/strtoul.3	Thu Nov 12 12:30:03 2015
@@ -1,4 +1,4 @@
-.\"	$NetBSD: strtoul.3,v 1.31 2015/05/03 12:29:28 wiz Exp $
+.\"	$NetBSD: strtoul.3,v 1.32 2015/11/12 17:30:03 christos Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -33,7 +33,7 @@
 .\"
 .\" from: @(#)strtoul.3	8.1 (Berkeley) 6/4/93
 .\"
-.Dd April 30, 2015
+.Dd November 15, 2015
 .Dt STRTOUL 3
 .Os
 .Sh NAME
@@ -113,8 +113,21 @@ If
 is zero or 16,
 the string may then include a
 .Ql 0x
+or
+.Ql 0X
+prefix,
+and the number will be read in base 16; otherwise,
+and the number will be read in base 16; otherwise,
+if the 
+.Fa base
+is zero or 2,
+the string may then include a
+.Ql 0b
+or
+.Ql 0B
 prefix,
-and the number will be read in base 16; otherwise, a zero

CVS commit: src/lib/libc/stdlib

2015-11-07 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sat Nov  7 18:47:26 UTC 2015

Modified Files:
src/lib/libc/stdlib: posix_memalign.3

Log Message:
Use Dv for NULL.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libc/stdlib/posix_memalign.3

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/stdlib/posix_memalign.3
diff -u src/lib/libc/stdlib/posix_memalign.3:1.2 src/lib/libc/stdlib/posix_memalign.3:1.3
--- src/lib/libc/stdlib/posix_memalign.3:1.2	Sat Nov  7 16:21:42 2015
+++ src/lib/libc/stdlib/posix_memalign.3	Sat Nov  7 18:47:26 2015
@@ -1,4 +1,4 @@
-.\"	$NetBSD: posix_memalign.3,v 1.2 2015/11/07 16:21:42 nros Exp $
+.\"	$NetBSD: posix_memalign.3,v 1.3 2015/11/07 18:47:26 wiz Exp $
 .\"
 .\" Copyright (C) 2006 Jason Evans .
 .\" All rights reserved.
@@ -49,7 +49,7 @@ The
 function allocates
 .Fa size
 bytes of memory such that the allocation's base address is an even multiple of
-.Fa alignment , 
+.Fa alignment ,
 and returns the allocation in the value pointed to by
 .Fa ptr .
 The requested
@@ -86,7 +86,9 @@ function returns the value 0 if successf
 The
 .Fn aligned_alloc
 function returns a pointer to the allocated memory if successful; on failure it
-returns NULL and sets
+returns
+.Dv NULL
+and sets
 .Fa errno
 to indicate the error.
 .Sh ERRORS



CVS commit: src/lib/libc/stdlib

2015-11-07 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sat Nov  7 18:46:37 UTC 2015

Modified Files:
src/lib/libc/stdlib: malloc.3

Log Message:
Sort SEE ALSO.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/lib/libc/stdlib/malloc.3

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/stdlib/malloc.3
diff -u src/lib/libc/stdlib/malloc.3:1.45 src/lib/libc/stdlib/malloc.3:1.46
--- src/lib/libc/stdlib/malloc.3:1.45	Sat Nov  7 16:21:42 2015
+++ src/lib/libc/stdlib/malloc.3	Sat Nov  7 18:46:37 2015
@@ -1,4 +1,4 @@
-.\" $NetBSD: malloc.3,v 1.45 2015/11/07 16:21:42 nros Exp $
+.\" $NetBSD: malloc.3,v 1.46 2015/11/07 18:46:37 wiz Exp $
 .\"
 .\" Copyright (c) 1980, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -247,13 +247,13 @@ size = newsize;
 .Xr madvise 2 ,
 .Xr mmap 2 ,
 .Xr sbrk 2 ,
+.Xr aligned_alloc 3 ,
 .Xr alloca 3 ,
 .Xr atexit 3 ,
 .Xr getpagesize 3 ,
 .Xr memory 3 ,
 .Xr posix_memalign 3 ,
-.Xr reallocarr 3 ,
-.Xr aligned_alloc 3
+.Xr reallocarr 3
 .Pp
 For the implementation details, see
 .Xr jemalloc 3 .



CVS commit: src/lib/libc/stdlib

2015-09-01 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Sep  1 19:39:57 UTC 2015

Modified Files:
src/lib/libc/stdlib: getopt_long.c

Log Message:
ANSIfy getopt(3) - this is the REPLACE_GETOPT version from getopt_long(3)

For the reference, this version still passes the current set of ATF tests
for the getopt(3) function.

This version is by default unused.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/lib/libc/stdlib/getopt_long.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/stdlib/getopt_long.c
diff -u src/lib/libc/stdlib/getopt_long.c:1.26 src/lib/libc/stdlib/getopt_long.c:1.27
--- src/lib/libc/stdlib/getopt_long.c:1.26	Tue Sep  1 01:28:17 2015
+++ src/lib/libc/stdlib/getopt_long.c	Tue Sep  1 19:39:57 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: getopt_long.c,v 1.26 2015/09/01 01:28:17 kamil Exp $	*/
+/*	$NetBSD: getopt_long.c,v 1.27 2015/09/01 19:39:57 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
 #endif
 
 #include 
-__RCSID("$NetBSD: getopt_long.c,v 1.26 2015/09/01 01:28:17 kamil Exp $");
+__RCSID("$NetBSD: getopt_long.c,v 1.27 2015/09/01 19:39:57 kamil Exp $");
 
 #include "namespace.h"
 
@@ -307,10 +307,7 @@ start:
  * [eventually this will replace the real getopt]
  */
 int
-getopt(nargc, nargv, options)
-	int nargc;
-	char * const *nargv;
-	const char *options;
+getopt(int nargc, char * const *nargv, const char *options)
 {
 	int retval;
 



CVS commit: src/lib/libc/stdlib

2015-08-31 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Sep  1 01:28:17 UTC 2015

Modified Files:
src/lib/libc/stdlib: getopt_long.c

Log Message:
Constness correction for the getopt(3) function under REPLACE_GETOPT

Use the __UNCONST() macro, which is used in the other parts for the same
argument nargv, but under the !REPLACE_GETOPT namespace.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/lib/libc/stdlib/getopt_long.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/stdlib/getopt_long.c
diff -u src/lib/libc/stdlib/getopt_long.c:1.25 src/lib/libc/stdlib/getopt_long.c:1.26
--- src/lib/libc/stdlib/getopt_long.c:1.25	Fri Mar 20 14:05:54 2009
+++ src/lib/libc/stdlib/getopt_long.c	Tue Sep  1 01:28:17 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: getopt_long.c,v 1.25 2009/03/20 14:05:54 joerg Exp $	*/
+/*	$NetBSD: getopt_long.c,v 1.26 2015/09/01 01:28:17 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
 #endif
 
 #include 
-__RCSID("$NetBSD: getopt_long.c,v 1.25 2009/03/20 14:05:54 joerg Exp $");
+__RCSID("$NetBSD: getopt_long.c,v 1.26 2015/09/01 01:28:17 kamil Exp $");
 
 #include "namespace.h"
 
@@ -326,7 +326,7 @@ getopt(nargc, nargv, options)
 		 */
 		if (nonopt_end != -1) {
 			permute_args(nonopt_start, nonopt_end, optind,
-   nargv);
+   __UNCONST(nargv));
 			optind -= nonopt_end - nonopt_start;
 		}
 		nonopt_start = nonopt_end = -1;



CVS commit: src/lib/libc/stdlib

2015-08-20 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Thu Aug 20 20:08:05 UTC 2015

Modified Files:
src/lib/libc/stdlib: reallocarr.c

Log Message:
Fix portability.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/stdlib/reallocarr.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/stdlib/reallocarr.c
diff -u src/lib/libc/stdlib/reallocarr.c:1.3 src/lib/libc/stdlib/reallocarr.c:1.4
--- src/lib/libc/stdlib/reallocarr.c:1.3	Tue Jul 28 17:13:34 2015
+++ src/lib/libc/stdlib/reallocarr.c	Thu Aug 20 20:08:04 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: reallocarr.c,v 1.3 2015/07/28 17:13:34 kamil Exp $ */
+/* $NetBSD: reallocarr.c,v 1.4 2015/08/20 20:08:04 joerg Exp $ */
 
 /*-
  * Copyright (c) 2015 Joerg Sonnenberger jo...@netbsd.org.
@@ -34,7 +34,7 @@
 #endif
 
 #include sys/cdefs.h
-__RCSID($NetBSD: reallocarr.c,v 1.3 2015/07/28 17:13:34 kamil Exp $);
+__RCSID($NetBSD: reallocarr.c,v 1.4 2015/08/20 20:08:04 joerg Exp $);
 
 #include namespace.h
 #include errno.h
@@ -50,7 +50,7 @@ __weak_alias(reallocarr, _reallocarr)
 #endif
 #endif
 
-#define SQRT_SIZE_MAX (1UL  (sizeof(size_t)  2))
+#define SQRT_SIZE_MAX (((size_t)1)  (sizeof(size_t) * CHAR_BIT / 2))
 
 #if !HAVE_REALLOCARR
 int



CVS commit: src/lib/libc/stdlib

2015-08-20 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Aug 20 22:27:49 UTC 2015

Modified Files:
src/lib/libc/stdlib: reallocarr.c

Log Message:
Minor alterations to reallocarr(3)

Add comment about division.
Mark error branches with __predict_false().
Reduce one branch with the OR trick.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libc/stdlib/reallocarr.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/stdlib/reallocarr.c
diff -u src/lib/libc/stdlib/reallocarr.c:1.4 src/lib/libc/stdlib/reallocarr.c:1.5
--- src/lib/libc/stdlib/reallocarr.c:1.4	Thu Aug 20 20:08:04 2015
+++ src/lib/libc/stdlib/reallocarr.c	Thu Aug 20 22:27:49 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: reallocarr.c,v 1.4 2015/08/20 20:08:04 joerg Exp $ */
+/* $NetBSD: reallocarr.c,v 1.5 2015/08/20 22:27:49 kamil Exp $ */
 
 /*-
  * Copyright (c) 2015 Joerg Sonnenberger jo...@netbsd.org.
@@ -34,7 +34,7 @@
 #endif
 
 #include sys/cdefs.h
-__RCSID($NetBSD: reallocarr.c,v 1.4 2015/08/20 20:08:04 joerg Exp $);
+__RCSID($NetBSD: reallocarr.c,v 1.5 2015/08/20 22:27:49 kamil Exp $);
 
 #include namespace.h
 #include errno.h
@@ -70,14 +70,20 @@ reallocarr(void *ptr, size_t number, siz
 		return 0;
 	}
 
-	if ((number = SQRT_SIZE_MAX || size = SQRT_SIZE_MAX) 
-	number  SIZE_MAX / size) {
+	/*
+	 * Try to avoid division here.
+	 *
+	 * It isn't possible to overflow during multiplication if neither
+	 * operand uses any of the most significant half of the bits.
+	 */
+	if (__predict_false((number|size) = SQRT_SIZE_MAX 
+	number  SIZE_MAX / size)) {
 		errno = saved_errno;
 		return EOVERFLOW;
 	}
 
 	nptr = realloc(optr, number * size);
-	if (nptr == NULL) {
+	if (__predict_false(nptr == NULL)) {
 		result = errno;
 	} else {
 		result = 0;



CVS commit: src/lib/libc/stdlib

2015-07-28 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Jul 28 17:13:34 UTC 2015

Modified Files:
src/lib/libc/stdlib: reallocarr.3 reallocarr.c

Log Message:
Compatibility fixes in reallocarr(3)

Make this work on !NetBSD platforms:
- replace __CTASSERT() with platform agnostic solution SQRT_SIZE_MAX
- include nbtool_config.h for cross builds to get definition of __RCSID()
- restore errno in the last rare code path for platforms affecting errno(2)
  in memcpy(2)

While there: rename parameter name 'num' to 'number' to be in sync with
the calloc(3) parameter naming.

Reported by scole_mail at the current-users ml.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/stdlib/reallocarr.3
cvs rdiff -u -r1.2 -r1.3 src/lib/libc/stdlib/reallocarr.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/stdlib/reallocarr.3
diff -u src/lib/libc/stdlib/reallocarr.3:1.3 src/lib/libc/stdlib/reallocarr.3:1.4
--- src/lib/libc/stdlib/reallocarr.3:1.3	Thu Feb 19 23:08:21 2015
+++ src/lib/libc/stdlib/reallocarr.3	Tue Jul 28 17:13:34 2015
@@ -1,4 +1,4 @@
-.\	$NetBSD: reallocarr.3,v 1.3 2015/02/19 23:08:21 wiz Exp $
+.\	$NetBSD: reallocarr.3,v 1.4 2015/07/28 17:13:34 kamil Exp $
 .\
 .\ Copyright (c) 2015 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -37,7 +37,7 @@
 .Ft int
 .Fo reallocarr
 .Fa void *ptr
-.Fa size_t num
+.Fa size_t number
 .Fa size_t size
 .Fc
 .Sh DESCRIPTION

Index: src/lib/libc/stdlib/reallocarr.c
diff -u src/lib/libc/stdlib/reallocarr.c:1.2 src/lib/libc/stdlib/reallocarr.c:1.3
--- src/lib/libc/stdlib/reallocarr.c:1.2	Thu Jul 16 00:03:59 2015
+++ src/lib/libc/stdlib/reallocarr.c	Tue Jul 28 17:13:34 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: reallocarr.c,v 1.2 2015/07/16 00:03:59 kamil Exp $ */
+/* $NetBSD: reallocarr.c,v 1.3 2015/07/28 17:13:34 kamil Exp $ */
 
 /*-
  * Copyright (c) 2015 Joerg Sonnenberger jo...@netbsd.org.
@@ -29,8 +29,12 @@
  * SUCH DAMAGE.
  */
 
+#if HAVE_NBTOOL_CONFIG_H
+#include nbtool_config.h
+#endif
+
 #include sys/cdefs.h
-__RCSID($NetBSD: reallocarr.c,v 1.2 2015/07/16 00:03:59 kamil Exp $);
+__RCSID($NetBSD: reallocarr.c,v 1.3 2015/07/28 17:13:34 kamil Exp $);
 
 #include namespace.h
 #include errno.h
@@ -40,16 +44,17 @@ __RCSID($NetBSD: reallocarr.c,v 1.2 201
 #include stdlib.h
 #include string.h
 
-__CTASSERT(65535  SIZE_MAX / 65535);
-
 #ifdef _LIBC
 #ifdef __weak_alias
 __weak_alias(reallocarr, _reallocarr)
 #endif
 #endif
 
+#define SQRT_SIZE_MAX (1UL  (sizeof(size_t)  2))
+
+#if !HAVE_REALLOCARR
 int
-reallocarr(void *ptr, size_t num, size_t size)
+reallocarr(void *ptr, size_t number, size_t size)
 {
 	int saved_errno, result;
 	void *optr;
@@ -57,16 +62,21 @@ reallocarr(void *ptr, size_t num, size_t
 
 	saved_errno = errno;
 	memcpy(optr, ptr, sizeof(ptr));
-	if (num == 0 || size == 0) {
+	if (number == 0 || size == 0) {
 		free(optr);
 		nptr = NULL;
 		memcpy(ptr, nptr, sizeof(ptr));
 		errno = saved_errno;
 		return 0;
 	}
-	if ((num = 65535 || size = 65535)  num  SIZE_MAX / size)
+
+	if ((number = SQRT_SIZE_MAX || size = SQRT_SIZE_MAX) 
+	number  SIZE_MAX / size) {
+		errno = saved_errno;
 		return EOVERFLOW;
-	nptr = realloc(optr, num * size);
+	}
+
+	nptr = realloc(optr, number * size);
 	if (nptr == NULL) {
 		result = errno;
 	} else {
@@ -76,3 +86,4 @@ reallocarr(void *ptr, size_t num, size_t
 	errno = saved_errno;
 	return result;
 }
+#endif



CVS commit: src/lib/libc/stdlib

2015-07-26 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Jul 26 17:09:29 UTC 2015

Modified Files:
src/lib/libc/stdlib: malloc.3

Log Message:
Add history of allocators

Idea accepted by christos
No objctions from riastradh


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/lib/libc/stdlib/malloc.3

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/stdlib/malloc.3
diff -u src/lib/libc/stdlib/malloc.3:1.42 src/lib/libc/stdlib/malloc.3:1.43
--- src/lib/libc/stdlib/malloc.3:1.42	Sun Jul 26 17:00:37 2015
+++ src/lib/libc/stdlib/malloc.3	Sun Jul 26 17:09:29 2015
@@ -1,4 +1,4 @@
-.\ $NetBSD: malloc.3,v 1.42 2015/07/26 17:00:37 kamil Exp $
+.\ $NetBSD: malloc.3,v 1.43 2015/07/26 17:09:29 kamil Exp $
 .\
 .\ Copyright (c) 1980, 1991, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -34,7 +34,7 @@
 .\ @(#)malloc.3	8.1 (Berkeley) 6/4/93
 .\ $FreeBSD: src/lib/libc/stdlib/malloc.3,v 1.73 2007/06/15 22:32:33 jasone Exp $
 .\
-.Dd February 5, 2015
+.Dd July 26, 2015
 .Dt MALLOC 3
 .Os
 .Sh NAME
@@ -265,3 +265,47 @@ and
 .Fn free
 functions conform to
 .St -isoC .
+.Sh HISTORY
+A
+.Fn free
+internal kernel function and a predecessor to
+.Fn malloc ,
+.Fn alloc ,
+first appeared in
+.At v1 .
+The C Library functions
+.Fn alloc
+and
+.Fn free
+appeared in
+.At v6 .
+The functions
+.Fn malloc ,
+.Fn calloc ,
+and
+.Fn realloc
+first appeared in
+.At v7 .
+.Pp
+A new implementation by Chris Kingsley was introduced in
+.Bx 4.2 ,
+followed by a complete rewrite by Poul-Henning Kamp (
+.Dq phk's malloc
+or
+.Dq new malloc )
+which appeared in
+.Fx 2.2
+and was included in
+.Nx  1.5
+and
+.Ox 2.0 .
+These implementations were all
+.Xr sbrk 2
+based.
+.Pp
+The
+.Fn jemalloc 3
+allocator became the default system allocator first in
+.Fx 7.0
+and then in
+.Nx 5.0 .



CVS commit: src/lib/libc/stdlib

2015-07-26 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Jul 26 17:00:37 UTC 2015

Modified Files:
src/lib/libc/stdlib: malloc.3

Log Message:
mandoc lint


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/lib/libc/stdlib/malloc.3

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/stdlib/malloc.3
diff -u src/lib/libc/stdlib/malloc.3:1.41 src/lib/libc/stdlib/malloc.3:1.42
--- src/lib/libc/stdlib/malloc.3:1.41	Fri Feb  6 08:37:39 2015
+++ src/lib/libc/stdlib/malloc.3	Sun Jul 26 17:00:37 2015
@@ -1,4 +1,4 @@
-.\ $NetBSD: malloc.3,v 1.41 2015/02/06 08:37:39 wiz Exp $
+.\ $NetBSD: malloc.3,v 1.42 2015/07/26 17:00:37 kamil Exp $
 .\
 .\ Copyright (c) 1980, 1991, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -212,7 +212,6 @@ if ((p = calloc(num, size)) == NULL)
 When using
 .Fn realloc ,
 one must be careful to avoid the following idiom:
-.Pp
 .Bd -literal -offset indent
 nsize += 50;
 



CVS commit: src/lib/libc/stdlib

2015-07-26 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Jul 26 17:03:06 UTC 2015

Modified Files:
src/lib/libc/stdlib: quick_exit.3

Log Message:
From Timo Buhrmester: Fix wrong parameter description


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libc/stdlib/quick_exit.3

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/stdlib/quick_exit.3
diff -u src/lib/libc/stdlib/quick_exit.3:1.2 src/lib/libc/stdlib/quick_exit.3:1.3
--- src/lib/libc/stdlib/quick_exit.3:1.2	Fri Apr 26 15:36:47 2013
+++ src/lib/libc/stdlib/quick_exit.3	Sun Jul 26 13:03:06 2015
@@ -1,4 +1,4 @@
-.\	$NetBSD: quick_exit.3,v 1.2 2013/04/26 19:36:47 wiz Exp $
+.\	$NetBSD: quick_exit.3,v 1.3 2015/07/26 17:03:06 christos Exp $
 .\  Copyright (c) 2011 David Chisnall
 .\  All rights reserved.
 .\
@@ -25,7 +25,7 @@
 .\
 .\  $FreeBSD: src/lib/libc/stdlib/quick_exit.3,v 1.4 2012/11/17 01:49:41 svnexp Exp $
 .\
-.Dd April 26, 2013
+.Dd July 26, 2015
 .Dt QUICK_EXIT 3
 .Os
 .Sh NAME
@@ -36,7 +36,7 @@
 .Sh SYNOPSIS
 .In stdlib.h
 .Ft _Noreturn void
-.Fn quick_exit void
+.Fn quick_exit int status
 .Sh DESCRIPTION
 The
 .Fn quick_exit
@@ -45,6 +45,15 @@ with
 .Xr at_quick_exit 3
 but not any C++ destructors or cleanup code registered with
 .Xr atexit 3 .
+.Pp
+The
+.Fa status
+values
+.Dv EXIT_SUCCESS
+and
+.Dv EXIT_FAILURE
+can be used to indicate successful and unsuccessful
+termination, respectively.
 .Sh RETURN VALUES
 The
 .Fn quick_exit



CVS commit: src/lib/libc/stdlib

2015-07-26 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Jul 26 17:21:55 UTC 2015

Modified Files:
src/lib/libc/stdlib: jemalloc.c

Log Message:
Defer using pthread keys until we are threaded.
From Christos, fixes PR port-arm/50087 by allowing malloc calls prior
to libpthread initialization.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/lib/libc/stdlib/jemalloc.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/stdlib/jemalloc.c
diff -u src/lib/libc/stdlib/jemalloc.c:1.37 src/lib/libc/stdlib/jemalloc.c:1.38
--- src/lib/libc/stdlib/jemalloc.c:1.37	Tue Jan 20 18:31:25 2015
+++ src/lib/libc/stdlib/jemalloc.c	Sun Jul 26 17:21:55 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: jemalloc.c,v 1.37 2015/01/20 18:31:25 christos Exp $	*/
+/*	$NetBSD: jemalloc.c,v 1.38 2015/07/26 17:21:55 martin Exp $	*/
 
 /*-
  * Copyright (C) 2006,2007 Jason Evans jas...@freebsd.org.
@@ -118,7 +118,7 @@
 
 #include sys/cdefs.h
 /* __FBSDID($FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.147 2007/06/15 22:00:16 jasone Exp $); */ 
-__RCSID($NetBSD: jemalloc.c,v 1.37 2015/01/20 18:31:25 christos Exp $);
+__RCSID($NetBSD: jemalloc.c,v 1.38 2015/07/26 17:21:55 martin Exp $);
 
 #ifdef __FreeBSD__
 #include libc_private.h
@@ -783,20 +783,58 @@ static unsigned		next_arena;
 static malloc_mutex_t	arenas_mtx; /* Protects arenas initialization. */
 #endif
 
-#ifndef NO_TLS
 /*
  * Map of pthread_self() -- arenas[???], used for selecting an arena to use
  * for allocations.
  */
-static __thread arena_t	*arenas_map;
-#define	get_arenas_map()	(arenas_map)
-#define	set_arenas_map(x)	(arenas_map = x)
+#ifndef NO_TLS
+static __thread arena_t	**arenas_map;
 #else
-#ifdef _REENTRANT
-static thread_key_t arenas_map_key;
+static arena_t	**arenas_map;
 #endif
-#define	get_arenas_map()	thr_getspecific(arenas_map_key)
-#define	set_arenas_map(x)	thr_setspecific(arenas_map_key, x)
+
+#if !defined(NO_TLS) || !defined(_REENTRANT)
+# define	get_arenas_map()	(arenas_map)
+# define	set_arenas_map(x)	(arenas_map = x)
+#else
+
+static thread_key_t arenas_map_key = -1;
+
+static inline arena_t **
+get_arenas_map(void)
+{
+	if (!__isthreaded)
+		return arenas_map;
+
+	if (arenas_map_key == -1) {
+		(void)thr_keycreate(arenas_map_key, NULL);
+		if (arenas_map != NULL) {
+			thr_setspecific(arenas_map_key, arenas_map);
+			arenas_map = NULL;
+		}
+	}
+
+	return thr_getspecific(arenas_map_key);
+}
+
+static __inline void
+set_arenas_map(arena_t **a)
+{
+	if (!__isthreaded) {
+		arenas_map = a;
+		return;
+	}
+
+	if (arenas_map_key == -1) {
+		(void)thr_keycreate(arenas_map_key, NULL);
+		if (arenas_map != NULL) {
+			_DIAGASSERT(arenas_map == a);
+			arenas_map = NULL;
+		}
+	}
+
+	thr_setspecific(arenas_map_key, a);
+}
 #endif
 
 #ifdef MALLOC_STATS
@@ -3654,11 +3692,6 @@ malloc_init_hard(void)
 		opt_narenas_lshift += 2;
 	}
 
-#ifdef NO_TLS
-	/* Initialize arena key. */
-	(void)thr_keycreate(arenas_map_key, NULL);
-#endif
-
 	/* Determine how many arenas to use. */
 	narenas = ncpus;
 	if (opt_narenas_lshift  0) {



CVS commit: src/lib/libc/stdlib

2015-07-26 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sun Jul 26 22:32:03 UTC 2015

Modified Files:
src/lib/libc/stdlib: malloc.3

Log Message:
Spacing; Fn - Xr for jemalloc.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/lib/libc/stdlib/malloc.3

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/stdlib/malloc.3
diff -u src/lib/libc/stdlib/malloc.3:1.43 src/lib/libc/stdlib/malloc.3:1.44
--- src/lib/libc/stdlib/malloc.3:1.43	Sun Jul 26 17:09:29 2015
+++ src/lib/libc/stdlib/malloc.3	Sun Jul 26 22:32:03 2015
@@ -1,4 +1,4 @@
-.\ $NetBSD: malloc.3,v 1.43 2015/07/26 17:09:29 kamil Exp $
+.\ $NetBSD: malloc.3,v 1.44 2015/07/26 22:32:03 wiz Exp $
 .\
 .\ Copyright (c) 1980, 1991, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -289,14 +289,14 @@ first appeared in
 .Pp
 A new implementation by Chris Kingsley was introduced in
 .Bx 4.2 ,
-followed by a complete rewrite by Poul-Henning Kamp (
-.Dq phk's malloc
+followed by a complete rewrite by Poul-Henning Kamp
+.Dq ( phk's malloc
 or
 .Dq new malloc )
 which appeared in
 .Fx 2.2
 and was included in
-.Nx  1.5
+.Nx 1.5
 and
 .Ox 2.0 .
 These implementations were all
@@ -304,7 +304,7 @@ These implementations were all
 based.
 .Pp
 The
-.Fn jemalloc 3
+.Xr jemalloc 3
 allocator became the default system allocator first in
 .Fx 7.0
 and then in



CVS commit: src/lib/libc/stdlib

2015-07-25 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Jul 26 02:22:33 UTC 2015

Modified Files:
src/lib/libc/stdlib: reallocarray.c

Log Message:
reallocarray(3) cleanup

Add missing NetBSD CVS Id
Don't define twice _OPENBSD_SOURCE


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libc/stdlib/reallocarray.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/stdlib/reallocarray.c
diff -u src/lib/libc/stdlib/reallocarray.c:1.4 src/lib/libc/stdlib/reallocarray.c:1.5
--- src/lib/libc/stdlib/reallocarray.c:1.4	Tue Mar 10 13:05:13 2015
+++ src/lib/libc/stdlib/reallocarray.c	Sun Jul 26 02:22:33 2015
@@ -1,3 +1,4 @@
+/*	$NetBSD: reallocarray.c,v 1.5 2015/07/26 02:22:33 kamil Exp $	*/
 /*	$OpenBSD: reallocarray.c,v 1.1 2014/05/08 21:43:49 deraadt Exp $	*/
 
 /*-
@@ -28,9 +29,9 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  */
-#define _OPENBSD_SOURCE
+
 #include sys/cdefs.h
-__RCSID($NetBSD: reallocarray.c,v 1.4 2015/03/10 13:05:13 christos Exp $);
+__RCSID($NetBSD: reallocarray.c,v 1.5 2015/07/26 02:22:33 kamil Exp $);
 
 #define _OPENBSD_SOURCE
 #include errno.h



CVS commit: src/lib/libc/stdlib

2015-07-25 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Jul 26 02:29:44 UTC 2015

Modified Files:
src/lib/libc/stdlib: reallocarray.3

Log Message:
Add license header (the NetBSD 2-clause version) with (C) TNF


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/stdlib/reallocarray.3

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/stdlib/reallocarray.3
diff -u src/lib/libc/stdlib/reallocarray.3:1.3 src/lib/libc/stdlib/reallocarray.3:1.4
--- src/lib/libc/stdlib/reallocarray.3:1.3	Fri Feb  6 08:37:39 2015
+++ src/lib/libc/stdlib/reallocarray.3	Sun Jul 26 02:29:44 2015
@@ -1,4 +1,31 @@
-.\ $NetBSD: reallocarray.3,v 1.3 2015/02/06 08:37:39 wiz Exp $
+.\ $NetBSD: reallocarray.3,v 1.4 2015/07/26 02:29:44 kamil Exp $
+.\
+.\ Copyright (c) 2015 The NetBSD Foundation, Inc.
+.\ 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.
+.\
+.\ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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
+.\ COPYRIGHT HOLDERS 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.
 .\
 .Dd February 5, 2015
 .Dt REALLOCARRAY 3



CVS commit: src/lib/libc/stdlib

2015-07-15 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Jul 16 00:04:00 UTC 2015

Modified Files:
src/lib/libc/stdlib: reallocarr.c

Log Message:
Reorder memcpy(3) and save errno

This chang is for safety as memcpy(3) might change it.

Approved by riastradh


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libc/stdlib/reallocarr.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/stdlib/reallocarr.c
diff -u src/lib/libc/stdlib/reallocarr.c:1.1 src/lib/libc/stdlib/reallocarr.c:1.2
--- src/lib/libc/stdlib/reallocarr.c:1.1	Tue Feb 17 20:29:21 2015
+++ src/lib/libc/stdlib/reallocarr.c	Thu Jul 16 00:03:59 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: reallocarr.c,v 1.1 2015/02/17 20:29:21 joerg Exp $ */
+/* $NetBSD: reallocarr.c,v 1.2 2015/07/16 00:03:59 kamil Exp $ */
 
 /*-
  * Copyright (c) 2015 Joerg Sonnenberger jo...@netbsd.org.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: reallocarr.c,v 1.1 2015/02/17 20:29:21 joerg Exp $);
+__RCSID($NetBSD: reallocarr.c,v 1.2 2015/07/16 00:03:59 kamil Exp $);
 
 #include namespace.h
 #include errno.h
@@ -55,8 +55,8 @@ reallocarr(void *ptr, size_t num, size_t
 	void *optr;
 	void *nptr;
 
-	memcpy(optr, ptr, sizeof(ptr));
 	saved_errno = errno;
+	memcpy(optr, ptr, sizeof(ptr));
 	if (num == 0 || size == 0) {
 		free(optr);
 		nptr = NULL;



CVS commit: src/lib/libc/stdlib

2015-07-11 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sat Jul 11 15:50:56 UTC 2015

Modified Files:
src/lib/libc/stdlib: strtoi.3

Log Message:
Add missing Fc which broke man page on the web. Remove superfluous Pp.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libc/stdlib/strtoi.3

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/stdlib/strtoi.3
diff -u src/lib/libc/stdlib/strtoi.3:1.2 src/lib/libc/stdlib/strtoi.3:1.3
--- src/lib/libc/stdlib/strtoi.3:1.2	Sun May  3 12:27:32 2015
+++ src/lib/libc/stdlib/strtoi.3	Sat Jul 11 15:50:56 2015
@@ -1,4 +1,4 @@
-.\	$NetBSD: strtoi.3,v 1.2 2015/05/03 12:27:32 wiz Exp $
+.\	$NetBSD: strtoi.3,v 1.3 2015/07/11 15:50:56 wiz Exp $
 .\
 .\ Copyright (c) 1990, 1991, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -54,6 +54,7 @@
 .Fa intmax_t lo
 .Fa intmax_t hi
 .Fa int *rstatus
+.Fc
 .Sh DESCRIPTION
 The
 .Fn strtoi
@@ -161,7 +162,6 @@ argument.
 The following example will always return a number in
 .Dv [1..99]
 range no matter what the input is, and warn if the conversion failed.
-.Pp
 .Bd -literal -offset indent
 int e;
 intmax_t lval = strtoi(buf, NULL, 0, 1, 99, e);



CVS commit: src/lib/libc/stdlib

2015-07-11 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sat Jul 11 15:51:33 UTC 2015

Modified Files:
src/lib/libc/stdlib: strtou.3

Log Message:
Add missing Fc.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libc/stdlib/strtou.3

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/stdlib/strtou.3
diff -u src/lib/libc/stdlib/strtou.3:1.2 src/lib/libc/stdlib/strtou.3:1.3
--- src/lib/libc/stdlib/strtou.3:1.2	Sun May  3 12:28:20 2015
+++ src/lib/libc/stdlib/strtou.3	Sat Jul 11 15:51:33 2015
@@ -1,4 +1,4 @@
-.\	$NetBSD: strtou.3,v 1.2 2015/05/03 12:28:20 wiz Exp $
+.\	$NetBSD: strtou.3,v 1.3 2015/07/11 15:51:33 wiz Exp $
 .\
 .\ Copyright (c) 1990, 1991, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -54,6 +54,7 @@
 .Fa uintmax_t lo
 .Fa uintmax_t hi
 .Fa int *rstatus
+.Fc
 .Sh DESCRIPTION
 The
 .Fn strtou



CVS commit: src/lib/libc/stdlib

2015-05-03 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sun May  3 12:29:28 UTC 2015

Modified Files:
src/lib/libc/stdlib: strtoul.3

Log Message:
Sort SEE ALSO.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/lib/libc/stdlib/strtoul.3

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/stdlib/strtoul.3
diff -u src/lib/libc/stdlib/strtoul.3:1.30 src/lib/libc/stdlib/strtoul.3:1.31
--- src/lib/libc/stdlib/strtoul.3:1.30	Fri May  1 14:17:56 2015
+++ src/lib/libc/stdlib/strtoul.3	Sun May  3 12:29:28 2015
@@ -1,4 +1,4 @@
-.\	$NetBSD: strtoul.3,v 1.30 2015/05/01 14:17:56 christos Exp $
+.\	$NetBSD: strtoul.3,v 1.31 2015/05/03 12:29:28 wiz Exp $
 .\
 .\ Copyright (c) 1990, 1991, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -247,10 +247,10 @@ The given string was out of range; the v
 .Xr atoll 3 ,
 .Xr strtod 3 ,
 .Xr strtoi 3 ,
+.Xr strtoimax 3 ,
 .Xr strtol 3 ,
 .Xr strtoll 3 ,
-.Xr strtoimax 3 ,
-.Xr strtou 3 ,
+.Xr strtou 3
 .Sh STANDARDS
 The
 .Fn strtoul



CVS commit: src/lib/libc/stdlib

2015-05-03 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sun May  3 12:28:20 UTC 2015

Modified Files:
src/lib/libc/stdlib: strtou.3

Log Message:
Sort ERRORS and SEE ALSO.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libc/stdlib/strtou.3

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/stdlib/strtou.3
diff -u src/lib/libc/stdlib/strtou.3:1.1 src/lib/libc/stdlib/strtou.3:1.2
--- src/lib/libc/stdlib/strtou.3:1.1	Fri May  1 14:17:56 2015
+++ src/lib/libc/stdlib/strtou.3	Sun May  3 12:28:20 2015
@@ -1,4 +1,4 @@
-.\	$NetBSD: strtou.3,v 1.1 2015/05/01 14:17:56 christos Exp $
+.\	$NetBSD: strtou.3,v 1.2 2015/05/03 12:28:20 wiz Exp $
 .\
 .\ Copyright (c) 1990, 1991, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -40,7 +40,7 @@
 .Dt STRTOU 3
 .Os
 .Sh NAME
-.Nm strtou 
+.Nm strtou
 .Nd convert a string to an uintmax_t integer
 .Sh LIBRARY
 .Lb libc
@@ -170,21 +170,20 @@ if (e)
 .Ed
 .Sh ERRORS
 .Bl -tag -width Er
+.It Bq Er ECANCELED
+The string did not contain any characters that were converted.
 .It Bq Er EINVAL
 The
 .Ar base
 is not between 2 and 36 and does not contain the special value 0.
-.It Bq Er ERANGE
-The given string was out of range; the value converted has been clamped.
-.It Bq Er ECANCELED
-The string did not contain any characters that were converted.
 .It Bq Er ENOTSUP
 The string contained non-numeric characters that did not get converted.
 In this case,
 .Fa endptr
 points to the first unconverted character.
 .It Bq Er ERANGE
-The range given was invalid, i.e.
+The given string was out of range; the value converted has been clamped; or
+the range given was invalid, i.e.
 .Fa lo
 \*[Gt]
 .Fa hi .
@@ -196,9 +195,9 @@ The range given was invalid, i.e.
 .Xr atoll 3 ,
 .Xr strtod 3 ,
 .Xr strtoi 3 ,
+.Xr strtoimax 3 ,
 .Xr strtol 3 ,
 .Xr strtoll 3 ,
-.Xr strtoimax 3 ,
 .Xr strtoul 3 ,
 .Xr strtoull 3 ,
 .Xr strtoumax 3



CVS commit: src/lib/libc/stdlib

2015-05-03 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sun May  3 12:27:32 UTC 2015

Modified Files:
src/lib/libc/stdlib: strtoi.3

Log Message:
Sort ERRORS and SEE ALSO.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libc/stdlib/strtoi.3

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/stdlib/strtoi.3
diff -u src/lib/libc/stdlib/strtoi.3:1.1 src/lib/libc/stdlib/strtoi.3:1.2
--- src/lib/libc/stdlib/strtoi.3:1.1	Fri May  1 14:17:56 2015
+++ src/lib/libc/stdlib/strtoi.3	Sun May  3 12:27:32 2015
@@ -1,4 +1,4 @@
-.\	$NetBSD: strtoi.3,v 1.1 2015/05/01 14:17:56 christos Exp $
+.\	$NetBSD: strtoi.3,v 1.2 2015/05/03 12:27:32 wiz Exp $
 .\
 .\ Copyright (c) 1990, 1991, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -171,21 +171,20 @@ if (e)
 .Ed
 .Sh ERRORS
 .Bl -tag -width Er
+.It Bq Er ECANCELED
+The string did not contain any characters that were converted.
 .It Bq Er EINVAL
 The
 .Ar base
 is not between 2 and 36 and does not contain the special value 0.
-.It Bq Er ERANGE
-The given string was out of range; the value converted has been clamped.
-.It Bq Er ECANCELED
-The string did not contain any characters that were converted.
 .It Bq Er ENOTSUP
 The string contained non-numeric characters that did not get converted.
 In this case,
 .Fa endptr
 points to the first unconverted character.
 .It Bq Er ERANGE
-The range given was invalid, i.e.
+The given string was out of range; the value converted has been clamped;
+or the range given was invalid, i.e.
 .Fa lo
 \*[Gt]
 .Fa hi .
@@ -196,9 +195,9 @@ The range given was invalid, i.e.
 .Xr atol 3 ,
 .Xr atoll 3 ,
 .Xr strtod 3 ,
+.Xr strtoimax 3 ,
 .Xr strtol 3 ,
 .Xr strtoll 3 ,
-.Xr strtoimax 3 ,
 .Xr strtou 3 ,
 .Xr strtoul 3 ,
 .Xr strtoull 3 ,



CVS commit: src/lib/libc/stdlib

2015-04-18 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sat Apr 18 21:44:31 UTC 2015

Modified Files:
src/lib/libc/stdlib: atexit.c

Log Message:
Add __aeabi_atexit alias for another case of NIH on ARM.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/lib/libc/stdlib/atexit.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/stdlib/atexit.c
diff -u src/lib/libc/stdlib/atexit.c:1.27 src/lib/libc/stdlib/atexit.c:1.28
--- src/lib/libc/stdlib/atexit.c:1.27	Tue Jan 20 18:31:25 2015
+++ src/lib/libc/stdlib/atexit.c	Sat Apr 18 21:44:31 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: atexit.c,v 1.27 2015/01/20 18:31:25 christos Exp $	*/
+/*	$NetBSD: atexit.c,v 1.28 2015/04/18 21:44:31 joerg Exp $	*/
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include sys/cdefs.h
 #if defined(LIBC_SCCS)  !defined(lint)
-__RCSID($NetBSD: atexit.c,v 1.27 2015/01/20 18:31:25 christos Exp $);
+__RCSID($NetBSD: atexit.c,v 1.28 2015/04/18 21:44:31 joerg Exp $);
 #endif /* LIBC_SCCS and not lint */
 
 #include reentrant.h
@@ -135,6 +135,10 @@ __libc_atexit_init(void)
  *
  *	http://www.codesourcery.com/cxx-abi/abi.html#dso-dtor
  */
+#if defined(__ARM_EABI__)  !defined(lint)
+__strong_alias(__aeabi_atexit,__cxa_atexit);
+#endif
+
 int
 __cxa_atexit(void (*func)(void *), void *arg, void *dso)
 {



CVS commit: src/lib/libc/stdlib

2015-03-11 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Wed Mar 11 09:57:35 UTC 2015

Modified Files:
src/lib/libc/stdlib: strtol.3

Log Message:
Use existing month for Dd.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/lib/libc/stdlib/strtol.3

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/stdlib/strtol.3
diff -u src/lib/libc/stdlib/strtol.3:1.30 src/lib/libc/stdlib/strtol.3:1.31
--- src/lib/libc/stdlib/strtol.3:1.30	Tue Mar 10 13:00:58 2015
+++ src/lib/libc/stdlib/strtol.3	Wed Mar 11 09:57:35 2015
@@ -1,4 +1,4 @@
-.\	$NetBSD: strtol.3,v 1.30 2015/03/10 13:00:58 christos Exp $
+.\	$NetBSD: strtol.3,v 1.31 2015/03/11 09:57:35 wiz Exp $
 .\
 .\ Copyright (c) 1990, 1991, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -33,7 +33,7 @@
 .\
 .\ from: @(#)strtol.3	8.1 (Berkeley) 6/4/93
 .\
-.Dd Match 10, 2015
+.Dd March 10, 2015
 .Dt STRTOL 3
 .Os
 .Sh NAME



CVS commit: src/lib/libc/stdlib

2015-03-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Mar 10 12:57:56 UTC 2015

Modified Files:
src/lib/libc/stdlib: strtonum.c

Log Message:
The OpenBSD strtonum() only accepts base 10 keywords. (Kamil Rytarowski)


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/stdlib/strtonum.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/stdlib/strtonum.c
diff -u src/lib/libc/stdlib/strtonum.c:1.3 src/lib/libc/stdlib/strtonum.c:1.4
--- src/lib/libc/stdlib/strtonum.c:1.3	Thu Feb  5 11:01:38 2015
+++ src/lib/libc/stdlib/strtonum.c	Tue Mar 10 08:57:56 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: strtonum.c,v 1.3 2015/02/05 16:01:38 christos Exp $	*/
+/*	$NetBSD: strtonum.c,v 1.4 2015/03/10 12:57:56 christos Exp $	*/
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -29,7 +29,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: strtonum.c,v 1.3 2015/02/05 16:01:38 christos Exp $);
+__RCSID($NetBSD: strtonum.c,v 1.4 2015/03/10 12:57:56 christos Exp $);
 
 #define _OPENBSD_SOURCE
 #include stdio.h
@@ -48,7 +48,7 @@ strtonum(const char *nptr, long long min
 	if (errstr == NULL)
 		errstr = resp;
 
-	rv = (long long)strtoi(nptr, NULL, 0, minval, maxval, e);
+	rv = (long long)strtoi(nptr, NULL, 10, minval, maxval, e);
 
 	if (e == 0) {
 		*errstr = NULL;



CVS commit: src/lib/libc/stdlib

2015-03-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Mar 10 13:00:58 UTC 2015

Modified Files:
src/lib/libc/stdlib: strtol.3 strtoul.3

Log Message:
PR/49640: Kamil Rytarowski: Improve error printing


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/lib/libc/stdlib/strtol.3
cvs rdiff -u -r1.28 -r1.29 src/lib/libc/stdlib/strtoul.3

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/stdlib/strtol.3
diff -u src/lib/libc/stdlib/strtol.3:1.29 src/lib/libc/stdlib/strtol.3:1.30
--- src/lib/libc/stdlib/strtol.3:1.29	Sun Jan 18 13:01:41 2015
+++ src/lib/libc/stdlib/strtol.3	Tue Mar 10 09:00:58 2015
@@ -1,4 +1,4 @@
-.\	$NetBSD: strtol.3,v 1.29 2015/01/18 18:01:41 christos Exp $
+.\	$NetBSD: strtol.3,v 1.30 2015/03/10 13:00:58 christos Exp $
 .\
 .\ Copyright (c) 1990, 1991, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -33,7 +33,7 @@
 .\
 .\ from: @(#)strtol.3	8.1 (Berkeley) 6/4/93
 .\
-.Dd December 27, 2014
+.Dd Match 10, 2015
 .Dt STRTOL 3
 .Os
 .Sh NAME
@@ -243,7 +243,7 @@ function is the simplest to use:
 int e;
 intmax_t lval = strtoi(buf, NULL, 0, 1, 99, e);
 if (e)
-	warn(conversion of `%s' to a number failed, using %jd,
+	warnc(e, conversion of `%s' to a number failed, using %jd,
 	buf, lval);
 .Ed
 .Pp

Index: src/lib/libc/stdlib/strtoul.3
diff -u src/lib/libc/stdlib/strtoul.3:1.28 src/lib/libc/stdlib/strtoul.3:1.29
--- src/lib/libc/stdlib/strtoul.3:1.28	Sun Jan 18 13:01:41 2015
+++ src/lib/libc/stdlib/strtoul.3	Tue Mar 10 09:00:58 2015
@@ -1,4 +1,4 @@
-.\	$NetBSD: strtoul.3,v 1.28 2015/01/18 18:01:41 christos Exp $
+.\	$NetBSD: strtoul.3,v 1.29 2015/03/10 13:00:58 christos Exp $
 .\
 .\ Copyright (c) 1990, 1991, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -33,7 +33,7 @@
 .\
 .\ from: @(#)strtoul.3	8.1 (Berkeley) 6/4/93
 .\
-.Dd December 27, 2014
+.Dd March 10, 2015
 .Dt STRTOUL 3
 .Os
 .Sh NAME
@@ -240,7 +240,7 @@ function is the simplest to use:
 int e;
 uintmax_t lval = strtou(buf, NULL, 0, 1, 99, e);
 if (e)
-	warn(conversion of `%s' to a number failed, using %ju,
+	warnc(e, conversion of `%s' to a number failed, using %ju,
 	buf, lval);
 .Ed
 .Pp



CVS commit: src/lib/libc/stdlib

2015-03-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Mar 10 13:05:13 UTC 2015

Modified Files:
src/lib/libc/stdlib: reallocarray.c

Log Message:
Behave in an OpenBSD compatible way for 0.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/stdlib/reallocarray.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/stdlib/reallocarray.c
diff -u src/lib/libc/stdlib/reallocarray.c:1.3 src/lib/libc/stdlib/reallocarray.c:1.4
--- src/lib/libc/stdlib/reallocarray.c:1.3	Tue Feb 17 15:44:42 2015
+++ src/lib/libc/stdlib/reallocarray.c	Tue Mar 10 09:05:13 2015
@@ -30,7 +30,7 @@
  */
 #define _OPENBSD_SOURCE
 #include sys/cdefs.h
-__RCSID($NetBSD: reallocarray.c,v 1.3 2015/02/17 20:44:42 christos Exp $);
+__RCSID($NetBSD: reallocarray.c,v 1.4 2015/03/10 13:05:13 christos Exp $);
 
 #define _OPENBSD_SOURCE
 #include errno.h
@@ -39,6 +39,9 @@ __RCSID($NetBSD: reallocarray.c,v 1.3 2
 void *
 reallocarray(void *optr, size_t nmemb, size_t size)
 {
+	if (nmemb == 0 || size == 0)
+		return realloc(optr, 0);
+
 	int e = reallocarr(optr, nmemb, size);
 
 	if (e == 0)



CVS commit: src/lib/libc/stdlib

2015-02-19 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Thu Feb 19 23:08:21 UTC 2015

Modified Files:
src/lib/libc/stdlib: reallocarr.3

Log Message:
Add EXAMPLES section, from Youri Mouton.
Bump date.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libc/stdlib/reallocarr.3

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/stdlib/reallocarr.3
diff -u src/lib/libc/stdlib/reallocarr.3:1.2 src/lib/libc/stdlib/reallocarr.3:1.3
--- src/lib/libc/stdlib/reallocarr.3:1.2	Wed Feb 18 08:46:43 2015
+++ src/lib/libc/stdlib/reallocarr.3	Thu Feb 19 23:08:21 2015
@@ -1,4 +1,4 @@
-.\	$NetBSD: reallocarr.3,v 1.2 2015/02/18 08:46:43 wiz Exp $
+.\	$NetBSD: reallocarr.3,v 1.3 2015/02/19 23:08:21 wiz Exp $
 .\
 .\ Copyright (c) 2015 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -26,7 +26,7 @@
 .\ 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.
-.Dd February 5, 2015
+.Dd February 19, 2015
 .Dt REALLOCARR 3
 .Os
 .Sh NAME
@@ -55,6 +55,23 @@ Otherwise, an error code (see
 is returned and
 .Fa *ptr
 and the referenced memory is unmodified.
+.Sh EXAMPLES
+The following uses
+.Fn reallocarr
+to initialize an array of INITSIZE integers, then
+resizes it to NEWSIZE elements:
+.Bd -literal -offset indent
+int *data = NULL;
+int ret = 0;
+
+ret = reallocarr(data, INITSIZE, sizeof(*data));
+if (ret)
+errc(1, ret, reallocarr failed);
+
+ret = reallocarr(data, NEWSIZE, sizeof(*data));
+if (ret)
+errc(1, ret, reallocarr failed on resize);
+.Ed
 .Sh SEE ALSO
 .Xr calloc 3
 .Sh HISTORY



  1   2   3   >