Module Name:    src
Committed By:   riastradh
Date:           Sat Nov  5 11:33:55 UTC 2022

Modified Files:
        src/lib/libc/regex: regerror.c

Log Message:
regerror(3): Allow null errbuf if errbuf_size is zero.

The man page says:

   If errbuf_size is 0, errbuf is ignored but the return value is still
   correct.

POSIX says:

   If errbuf_size is 0, regerror() shall ignore the errbuf argument,
   and return the size of the buffer needed to hold the generated
   string.

   https://pubs.opengroup.org/onlinepubs/9699919799/functions/regerror.html

from [email protected]


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/lib/libc/regex/regerror.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/regex/regerror.c
diff -u src/lib/libc/regex/regerror.c:1.25 src/lib/libc/regex/regerror.c:1.26
--- src/lib/libc/regex/regerror.c:1.25	Fri Feb 26 19:24:47 2021
+++ src/lib/libc/regex/regerror.c	Sat Nov  5 11:33:55 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: regerror.c,v 1.25 2021/02/26 19:24:47 christos Exp $	*/
+/*	$NetBSD: regerror.c,v 1.26 2022/11/05 11:33:55 riastradh Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-3-Clause
@@ -46,7 +46,7 @@
 static char sccsid[] = "@(#)regerror.c	8.4 (Berkeley) 3/20/94";
 __FBSDID("$FreeBSD: head/lib/libc/regex/regerror.c 326025 2017-11-20 19:49:47Z pfg $");
 #endif
-__RCSID("$NetBSD: regerror.c,v 1.25 2021/02/26 19:24:47 christos Exp $");
+__RCSID("$NetBSD: regerror.c,v 1.26 2022/11/05 11:33:55 riastradh Exp $");
 
 #include "namespace.h"
 #include <sys/types.h>
@@ -139,7 +139,7 @@ regerror(int errcode,
 	char convbuf[50];
 
 	_DIAGASSERT(errcode != REG_ATOI || preg != NULL);
-	_DIAGASSERT(errbuf != NULL);
+	_DIAGASSERT(errbuf_size == 0 || errbuf != NULL);
 
 	if (errcode == REG_ATOI) {
 		s = regatoi(preg, convbuf, sizeof convbuf);

Reply via email to