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

2024-07-24 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Jul 24 09:11:28 UTC 2024

Modified Files:
src/common/lib/libc/stdlib: _strtoi.h

Log Message:
PR lib/58461  PR lib/58453 portability fixes

Revert previous (1.4) and make the changes properly.

If base is invalid, what gets left in *endptr by strtoimax()
is unspecified (it is not guaranteed to be either nptr or unaltered)
and so cannot (in that case) be used in any way at all.

Since it is hard to determine from some implementations of
strtoimax() whether this happened or not, simply duplicate
the validity test for base here, so we know that error (EINVAL
because base is invalid) cannot occur from strtoimax().   In that
case, if we get an EINVAL from strtoimax we can simply ignore it,
as all it can mean is the (optional in POSIX) case where no
conversion occurred (where strtoi() sets the status to ECANCELED).

Since NetBSD never did that, this all changes nothing here, but
makes strtoi() portable to other environments using a different
version of strtoimax().

NFCI.

No pullups required, nothing has really changed, there never was
a NetBSD bug to fix.


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

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

Modified files:

Index: src/common/lib/libc/stdlib/_strtoi.h
diff -u src/common/lib/libc/stdlib/_strtoi.h:1.4 src/common/lib/libc/stdlib/_strtoi.h:1.5
--- src/common/lib/libc/stdlib/_strtoi.h:1.4	Sun Jul 21 17:40:42 2024
+++ src/common/lib/libc/stdlib/_strtoi.h	Wed Jul 24 09:11:27 2024
@@ -1,9 +1,8 @@
-/*	$NetBSD: _strtoi.h,v 1.4 2024/07/21 17:40:42 christos Exp $	*/
+/*	$NetBSD: _strtoi.h,v 1.5 2024/07/24 09:11:27 kre Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
- * Copyright (c) 2024, Alejandro Colomar 
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -70,7 +69,7 @@ INT_FUNCNAME(_int_, _FUNCNAME, _l)(const
 	int serrno;
 #endif
 	__TYPE im;
-	char *e;
+	char *ep;
 	int rep;
 
 	_DIAGASSERT(hi >= lo);
@@ -78,11 +77,26 @@ INT_FUNCNAME(_int_, _FUNCNAME, _l)(const
 	_DIAGASSERT(nptr != NULL);
 	/* endptr may be NULL */
 
-	e = NULL;
+	if (endptr == NULL)
+		endptr = 
 
 	if (rstatus == NULL)
 		rstatus = 
 
+	*rstatus = 0;		/* assume there will be no errors */
+
+	if (base != 0 && (base < 2 || base > 36)) {
+#if !defined(_KERNEL) && !defined(_STANDALONE)
+		*rstatus = EINVAL;
+		if (endptr != NULL)
+			/* LINTED interface specification */
+			*endptr = __UNCONST(nptr);
+		return 0;
+#else
+		panic("%s: invalid base %d", __func__, base);
+#endif
+	}
+
 #if !defined(_KERNEL) && !defined(_STANDALONE)
 	serrno = errno;
 	errno = 0;
@@ -90,21 +104,20 @@ INT_FUNCNAME(_int_, _FUNCNAME, _l)(const
 
 #if defined(_KERNEL) || defined(_STANDALONE) || \
 defined(HAVE_NBTOOL_CONFIG_H) || defined(BCS_ONLY)
-	im = __WRAPPED(nptr, , base);
+	im = __WRAPPED(nptr, endptr, base);
 #else
-	im = __WRAPPED_L(nptr, , base, loc);
+	im = __WRAPPED_L(nptr, endptr, base, loc);
 #endif
 
 #if !defined(_KERNEL) && !defined(_STANDALONE)
-	*rstatus = errno;
+	/* EINVAL here can only mean "nothing converted" */
+	if (errno != EINVAL)
+		*rstatus = errno;
 	errno = serrno;
 #endif
 
-	if (endptr != NULL && e != NULL)
-		*endptr = e;
-
 	/* No digits were found */
-	if (nptr == e && (*rstatus == 0 || *rstatus == EINVAL))
+	if (*rstatus == 0 && nptr == *endptr)
 		*rstatus = ECANCELED;
 
 	if (im < lo) {
@@ -120,7 +133,7 @@ INT_FUNCNAME(_int_, _FUNCNAME, _l)(const
 	}
 
 	/* There are further characters after number */
-	if (*rstatus == 0 && *e != '\0')
+	if (*rstatus == 0 && **endptr != '\0')
 		*rstatus = ENOTSUP;
 
 	return im;



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

2024-07-24 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Jul 24 09:11:28 UTC 2024

Modified Files:
src/common/lib/libc/stdlib: _strtoi.h

Log Message:
PR lib/58461  PR lib/58453 portability fixes

Revert previous (1.4) and make the changes properly.

If base is invalid, what gets left in *endptr by strtoimax()
is unspecified (it is not guaranteed to be either nptr or unaltered)
and so cannot (in that case) be used in any way at all.

Since it is hard to determine from some implementations of
strtoimax() whether this happened or not, simply duplicate
the validity test for base here, so we know that error (EINVAL
because base is invalid) cannot occur from strtoimax().   In that
case, if we get an EINVAL from strtoimax we can simply ignore it,
as all it can mean is the (optional in POSIX) case where no
conversion occurred (where strtoi() sets the status to ECANCELED).

Since NetBSD never did that, this all changes nothing here, but
makes strtoi() portable to other environments using a different
version of strtoimax().

NFCI.

No pullups required, nothing has really changed, there never was
a NetBSD bug to fix.


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

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



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

2024-07-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Jul 21 17:40:42 UTC 2024

Modified Files:
src/common/lib/libc/stdlib: _strtoi.h

Log Message:
POSIX allows systems that report EINVAL when no digits are found. On
such systems the only way to differentiate EINVAL and ECANCELED is to
initialized the end pointer to NULL before the call. On EINVAL cases,
strto*max(3) will leave the pointer unmodified, so we'll read back the
original NULL. On ECANCELED cases, strto*max(3) will set it to nptr.
This also prevents UB read of endptr on an unsupported base argument.
(Alejandro Colomar)


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

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

Modified files:

Index: src/common/lib/libc/stdlib/_strtoi.h
diff -u src/common/lib/libc/stdlib/_strtoi.h:1.3 src/common/lib/libc/stdlib/_strtoi.h:1.4
--- src/common/lib/libc/stdlib/_strtoi.h:1.3	Sat Jan 20 11:13:39 2024
+++ src/common/lib/libc/stdlib/_strtoi.h	Sun Jul 21 13:40:42 2024
@@ -1,8 +1,9 @@
-/*	$NetBSD: _strtoi.h,v 1.3 2024/01/20 16:13:39 christos Exp $	*/
+/*	$NetBSD: _strtoi.h,v 1.4 2024/07/21 17:40:42 christos Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
+ * Copyright (c) 2024, Alejandro Colomar 
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -69,7 +70,7 @@ INT_FUNCNAME(_int_, _FUNCNAME, _l)(const
 	int serrno;
 #endif
 	__TYPE im;
-	char *ep;
+	char *e;
 	int rep;
 
 	_DIAGASSERT(hi >= lo);
@@ -77,8 +78,7 @@ INT_FUNCNAME(_int_, _FUNCNAME, _l)(const
 	_DIAGASSERT(nptr != NULL);
 	/* endptr may be NULL */
 
-	if (endptr == NULL)
-		endptr = 
+	e = NULL;
 
 	if (rstatus == NULL)
 		rstatus = 
@@ -90,9 +90,9 @@ INT_FUNCNAME(_int_, _FUNCNAME, _l)(const
 
 #if defined(_KERNEL) || defined(_STANDALONE) || \
 defined(HAVE_NBTOOL_CONFIG_H) || defined(BCS_ONLY)
-	im = __WRAPPED(nptr, endptr, base);
+	im = __WRAPPED(nptr, , base);
 #else
-	im = __WRAPPED_L(nptr, endptr, base, loc);
+	im = __WRAPPED_L(nptr, , base, loc);
 #endif
 
 #if !defined(_KERNEL) && !defined(_STANDALONE)
@@ -100,8 +100,11 @@ INT_FUNCNAME(_int_, _FUNCNAME, _l)(const
 	errno = serrno;
 #endif
 
+	if (endptr != NULL && e != NULL)
+		*endptr = e;
+
 	/* No digits were found */
-	if (*rstatus == 0 && nptr == *endptr)
+	if (nptr == e && (*rstatus == 0 || *rstatus == EINVAL))
 		*rstatus = ECANCELED;
 
 	if (im < lo) {
@@ -117,7 +120,7 @@ INT_FUNCNAME(_int_, _FUNCNAME, _l)(const
 	}
 
 	/* There are further characters after number */
-	if (*rstatus == 0 && **endptr != '\0')
+	if (*rstatus == 0 && *e != '\0')
 		*rstatus = ENOTSUP;
 
 	return im;



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

2024-07-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Jul 21 17:40:42 UTC 2024

Modified Files:
src/common/lib/libc/stdlib: _strtoi.h

Log Message:
POSIX allows systems that report EINVAL when no digits are found. On
such systems the only way to differentiate EINVAL and ECANCELED is to
initialized the end pointer to NULL before the call. On EINVAL cases,
strto*max(3) will leave the pointer unmodified, so we'll read back the
original NULL. On ECANCELED cases, strto*max(3) will set it to nptr.
This also prevents UB read of endptr on an unsupported base argument.
(Alejandro Colomar)


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

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



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

2024-06-29 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sat Jun 29 07:56:57 UTC 2024

Modified Files:
src/common/lib/libc/stdlib: getopt.c

Log Message:
getopt(): Make this built for _KERNEL || _STANDALONE

NFC as a libc routine.


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

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

Modified files:

Index: src/common/lib/libc/stdlib/getopt.c
diff -u src/common/lib/libc/stdlib/getopt.c:1.1 src/common/lib/libc/stdlib/getopt.c:1.2
--- src/common/lib/libc/stdlib/getopt.c:1.1	Sat Jun 29 07:55:05 2024
+++ src/common/lib/libc/stdlib/getopt.c	Sat Jun 29 07:56:56 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: getopt.c,v 1.1 2024/06/29 07:55:05 rin Exp $	*/
+/*	$NetBSD: getopt.c,v 1.2 2024/06/29 07:56:56 rin Exp $	*/
 
 /*
  * Copyright (c) 1987, 1993, 1994
@@ -30,7 +30,16 @@
  */
 
 #include 
-__RCSID("$NetBSD: getopt.c,v 1.1 2024/06/29 07:55:05 rin Exp $");
+__RCSID("$NetBSD: getopt.c,v 1.2 2024/06/29 07:56:56 rin Exp $");
+
+#if defined(_KERNEL) || defined(_STANDALONE)
+
+#include 
+#include 
+
+#define	EPRINTF(fmt, args...)	printf(fmt, ##args)
+
+#else
 
 #include "namespace.h"
 
@@ -45,6 +54,11 @@ __RCSID("$NetBSD: getopt.c,v 1.1 2024/06
 __weak_alias(getopt,_getopt)
 #endif
 
+#define	EPRINTF(fmt, args...)		\
+fprintf(stderr, "%s: " fmt, getprogname(), ##args)
+
+#endif /* !_KERNEL && !_STANDALONE */
+
 int	opterr = 1,		/* if error message should be printed */
 	optind = 1,		/* index into parent argv vector */
 	optopt,			/* character checked for validity */
@@ -99,9 +113,7 @@ getopt(int nargc, char * const nargv[], 
 		if (*place == 0)
 			++optind;
 		if (opterr && *ostr != ':')
-			(void)fprintf(stderr,
-			"%s: unknown option -- %c\n", getprogname(),
-			optopt);
+			(void)EPRINTF("unknown option -- %c\n", optopt);
 		return (BADCH);
 	}
 
@@ -130,9 +142,9 @@ getopt(int nargc, char * const nargv[], 
 			if (*ostr == ':')
 return (BADARG);
 			if (opterr)
-(void)fprintf(stderr,
-"%s: option requires an argument -- %c\n",
-getprogname(), optopt);
+(void)EPRINTF(
+"option requires an argument -- %c\n",
+optopt);
 			return (BADCH);
 		}
 		place = EMSG;



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

2024-06-29 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sat Jun 29 07:56:57 UTC 2024

Modified Files:
src/common/lib/libc/stdlib: getopt.c

Log Message:
getopt(): Make this built for _KERNEL || _STANDALONE

NFC as a libc routine.


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

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



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

2019-11-28 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Thu Nov 28 12:33:23 UTC 2019

Modified Files:
src/common/lib/libc/stdlib: strtoi.c strtou.c

Log Message:
Make it easier to use strtoi and strtou in downsteam applications
without the need to define HAVE_NBTOOL_CONFIG_H and yet allow -Wundef
not to log any warnings.


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

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

Modified files:

Index: src/common/lib/libc/stdlib/strtoi.c
diff -u src/common/lib/libc/stdlib/strtoi.c:1.2 src/common/lib/libc/stdlib/strtoi.c:1.3
--- src/common/lib/libc/stdlib/strtoi.c:1.2	Fri May  1 14:17:56 2015
+++ src/common/lib/libc/stdlib/strtoi.c	Thu Nov 28 12:33:23 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: strtoi.c,v 1.2 2015/05/01 14:17:56 christos Exp $	*/
+/*	$NetBSD: strtoi.c,v 1.3 2019/11/28 12:33:23 roy Exp $	*/
 
 /*-
  * Copyright (c) 2005 The DragonFly Project.  All rights reserved.
@@ -30,12 +30,12 @@
  * NetBSD: src/common/lib/libc/stdlib/strtoul.c,v 1.3 2008/08/20 19:58:34 oster Exp
  */
 
-#if HAVE_NBTOOL_CONFIG_H
+#if defined(HAVE_NBTOOL_CONFIG_H) && HAVE_NBTOOL_CONFIG_H
 #include "nbtool_config.h"
 #endif
 
 #include 
-__RCSID("$NetBSD: strtoi.c,v 1.2 2015/05/01 14:17:56 christos Exp $");
+__RCSID("$NetBSD: strtoi.c,v 1.3 2019/11/28 12:33:23 roy Exp $");
 
 #ifdef _LIBC
 #include "namespace.h"
Index: src/common/lib/libc/stdlib/strtou.c
diff -u src/common/lib/libc/stdlib/strtou.c:1.2 src/common/lib/libc/stdlib/strtou.c:1.3
--- src/common/lib/libc/stdlib/strtou.c:1.2	Fri May  1 14:17:56 2015
+++ src/common/lib/libc/stdlib/strtou.c	Thu Nov 28 12:33:23 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: strtou.c,v 1.2 2015/05/01 14:17:56 christos Exp $	*/
+/*	$NetBSD: strtou.c,v 1.3 2019/11/28 12:33:23 roy Exp $	*/
 
 /*-
  * Copyright (c) 2005 The DragonFly Project.  All rights reserved.
@@ -30,12 +30,12 @@
  * NetBSD: src/common/lib/libc/stdlib/strtoul.c,v 1.3 2008/08/20 19:58:34 oster Exp
  */
 
-#if HAVE_NBTOOL_CONFIG_H
+#if defined(HAVE_NBTOOL_CONFIG_H) && HAVE_NBTOOL_CONFIG_H
 #include "nbtool_config.h"
 #endif
 
 #include 
-__RCSID("$NetBSD: strtou.c,v 1.2 2015/05/01 14:17:56 christos Exp $");
+__RCSID("$NetBSD: strtou.c,v 1.3 2019/11/28 12:33:23 roy Exp $");
 
 #ifdef _LIBC
 #include "namespace.h"



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

2019-11-28 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Thu Nov 28 12:33:23 UTC 2019

Modified Files:
src/common/lib/libc/stdlib: strtoi.c strtou.c

Log Message:
Make it easier to use strtoi and strtou in downsteam applications
without the need to define HAVE_NBTOOL_CONFIG_H and yet allow -Wundef
not to log any warnings.


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

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



Re: CVS commit: src/common/lib/libc/stdlib

2016-01-13 Thread Kamil Rytarowski
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

On 12.01.2016 22:43, David Laight wrote:
> On Sat, Nov 14, 2015 at 06:40:21AM +1100, matthew green wrote:
>> Christos Zoulas writes:
>>> In article <2015111344.ga13...@britannica.bec.de>, Joerg
>>> Sonnenberger   wrote:
 On Thu, Nov 12, 2015 at 12:23:51PM -0500, Christos Zoulas
 wrote:
> Module Name:  src Committed By:   christos Date:  Thu Nov 
> 12
> 17:23:51 UTC 2015
> 
> Modified Files: src/common/lib/libc/stdlib: _strtol.h
> _strtoul.h
> 
> Log Message: Recognize 0[bB] as binary (base 2)
 
 Based on what authority? This is a ISO C function and that
 doesn't allow binary input. I am quite concerned about
 changing a function used that often, especially as it can
 break a lot of existing code.
>>> 
>>> I don't think it will since it will only affect conversions
>>> with 0[bB], and the OS/X code is doing the same, but I will
>>> revert it until others catch up.
>> 
>> the problem is that something that was "0b" always
>> came out as 0 before, but now it doesn't.
>> 
>> that's a fairly major semantic change, i think i agree with joerg
>> that it has a high chance of breaking existing usage.
> 
> Worse that that, some code might be relying on getting a pointer to
> the 'b' and continuing to parse the buffer.
> 
> Not a good idea to change it.
> 
> David
> 

The 0B or 0b syntax is a part of C++14 and part of C compilers
recognize it for at least a decade. It's common in other languages
(Java, D, Ruby, Python)

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3472.pdf

But it's still not officially supported by strtol(3)-like functions in
C/C++.

I would support it as a local extensions, it makes sense to me.

There might be a conflict with strsuftoll(3) (hopefully once replaced
by strsuftoi(3)) for '0b' but it's a narrow-case and not from a
real-life usage.
-BEGIN PGP SIGNATURE-
Version: GnuPG v2

iQIcBAEBCAAGBQJWlqd1AAoJEEuzCOmwLnZss/oQAMLZVikU+NlqrC+j5Qyq8w/J
u7KEvgXP4j/uo6tWkc1q9sbMDyrH9FIF1T+wtpAppmxU1k2B2rFTSs/sqcDq+B1V
8pJBZt97+eyra7fbc9uy6pP8jZu9Wuvay+Uu0zoJxSlvThmF5+uPpLPA8D/lvKcP
Gvnx9aBDk01Hloltyg7D1A7VpH0zcc+EH+f3oIe4Jckkkm06OulhN5YacXszyaF2
14X77cqFVTsB5v1+UWDoi95e10X8My5UAYgn9efJHk+b75BxQAggm4kJ8YG84OyV
CjuqpuakWQ+N/3tQarV7laLjCxwuX7CVe5qDpzmCcCTLO6wIIk6gXOqOwQHn9/Qm
0SFW/aHhocXn7l4eTjMd/rjpuzScgrt21PB+UcrHQAkBjaXZB1w1MvvgYsHcseWm
OXSVeR0W+wPplgegs2dCpUa9VGh/m3fxbHOTW+Ac4rBwRKk9BjalOUhj/IG7Acy5
5pl+YAwmCsIcSsHI1JUsL+aJVgLz0jsC+oqT3VyV7txz7Z5OXpRB+j/LW7tHYg0F
gIXLGwka8mToTtRxuNeVby4vITsjR3qaJmhVlX8j0mqHsbWxwnc83mUcmmT6vnkc
tvDbLt022FS1TvEEFEInDeMhe0QX5j+rqTb3ft5rYww4CmEnOiTvYRAsh2LqLPhJ
3VLpHPeT9ouMUwVzHIrm
=fXts
-END PGP SIGNATURE-


Re: CVS commit: src/common/lib/libc/stdlib

2016-01-12 Thread David Laight
On Sat, Nov 14, 2015 at 06:40:21AM +1100, matthew green wrote:
> Christos Zoulas writes:
> > In article <2015111344.ga13...@britannica.bec.de>,
> > Joerg Sonnenberger   wrote:
> > >On Thu, Nov 12, 2015 at 12:23:51PM -0500, Christos Zoulas wrote:
> > >> Module Name: src
> > >> Committed By:christos
> > >> Date:Thu Nov 12 17:23:51 UTC 2015
> > >> 
> > >> Modified Files:
> > >>  src/common/lib/libc/stdlib: _strtol.h _strtoul.h
> > >> 
> > >> Log Message:
> > >> Recognize 0[bB] as binary (base 2)
> > >
> > >Based on what authority? This is a ISO C function and that doesn't allow
> > >binary input. I am quite concerned about changing a function used that
> > >often, especially as it can break a lot of existing code.
> > 
> > I don't think it will since it will only affect conversions with 0[bB],
> > and the OS/X code is doing the same, but I will revert it until others
> > catch up.
> 
> the problem is that something that was "0b" always came out
> as 0 before, but now it doesn't.
> 
> that's a fairly major semantic change, i think i agree with joerg that
> it has a high chance of breaking existing usage.

Worse that that, some code might be relying on getting a pointer
to the 'b' and continuing to parse the buffer.

Not a good idea to change it.

David

-- 
David Laight: da...@l8s.co.uk


Re: CVS commit: src/common/lib/libc/stdlib

2015-11-13 Thread Joerg Sonnenberger
On Thu, Nov 12, 2015 at 12:23:51PM -0500, Christos Zoulas wrote:
> Module Name:  src
> Committed By: christos
> Date: Thu Nov 12 17:23:51 UTC 2015
> 
> Modified Files:
>   src/common/lib/libc/stdlib: _strtol.h _strtoul.h
> 
> Log Message:
> Recognize 0[bB] as binary (base 2)

Based on what authority? This is a ISO C function and that doesn't allow
binary input. I am quite concerned about changing a function used that
often, especially as it can break a lot of existing code.

Joerg


Re: CVS commit: src/common/lib/libc/stdlib

2015-11-13 Thread Christos Zoulas
In article <2015111344.ga13...@britannica.bec.de>,
Joerg Sonnenberger   wrote:
>On Thu, Nov 12, 2015 at 12:23:51PM -0500, Christos Zoulas wrote:
>> Module Name: src
>> Committed By:christos
>> Date:Thu Nov 12 17:23:51 UTC 2015
>> 
>> Modified Files:
>>  src/common/lib/libc/stdlib: _strtol.h _strtoul.h
>> 
>> Log Message:
>> Recognize 0[bB] as binary (base 2)
>
>Based on what authority? This is a ISO C function and that doesn't allow
>binary input. I am quite concerned about changing a function used that
>often, especially as it can break a lot of existing code.

I don't think it will since it will only affect conversions with 0[bB],
and the OS/X code is doing the same, but I will revert it until others
catch up.

christos



re: CVS commit: src/common/lib/libc/stdlib

2015-11-13 Thread matthew green
Christos Zoulas writes:
> In article <2015111344.ga13...@britannica.bec.de>,
> Joerg Sonnenberger   wrote:
> >On Thu, Nov 12, 2015 at 12:23:51PM -0500, Christos Zoulas wrote:
> >> Module Name:   src
> >> Committed By:  christos
> >> Date:  Thu Nov 12 17:23:51 UTC 2015
> >> 
> >> Modified Files:
> >>src/common/lib/libc/stdlib: _strtol.h _strtoul.h
> >> 
> >> Log Message:
> >> Recognize 0[bB] as binary (base 2)
> >
> >Based on what authority? This is a ISO C function and that doesn't allow
> >binary input. I am quite concerned about changing a function used that
> >often, especially as it can break a lot of existing code.
> 
> I don't think it will since it will only affect conversions with 0[bB],
> and the OS/X code is doing the same, but I will revert it until others
> catch up.

the problem is that something that was "0b" always came out
as 0 before, but now it doesn't.

that's a fairly major semantic change, i think i agree with joerg that
it has a high chance of breaking existing usage.


.mrg.


Re: CVS commit: src/common/lib/libc/stdlib

2013-12-02 Thread Lourival Vieira Neto
 Module Name:src
 Committed By:   joerg
 Date:   Mon Dec  2 12:20:44 UTC 2013

 Modified Files:
src/common/lib/libc/stdlib: strtoimax.c

 Log Message:
 Fix aliases.

Sorry about that.. my bad!

Regards,
-- 
Lourival Vieira Neto


Re: CVS commit: src/common/lib/libc/stdlib

2013-04-16 Thread David Laight
On Tue, Apr 16, 2013 at 07:34:58PM +, Joerg Sonnenberger wrote:
 Module Name:  src
 Committed By: joerg
 Date: Tue Apr 16 19:34:58 UTC 2013
 
 Modified Files:
   src/common/lib/libc/stdlib: _strtol.h _strtoul.h
 
 Log Message:
 Do not use isalpha here, since we explicitly only support the Portable
 Character Set as base and in theory a locale could define a ASCII
 control character as letter, resulting in negations. Also avoid isdigit
 here to give the compiler a better chance of deciding whether an
 unsigned compare or a jump table is a better option, both are very
 likely better choices than the memory indirection.

There really ought to be a way of requesting the straight ASCII
versions of the is functions even after a local has been set.
A lot of code will use isalpha() to check for valid variable names (etc)
and really doesn't want locale-specific alpha characters be valid.
(Otherwise scripts become non-portable.)

OTOH (unsigned)(ch - '0') = 9 is probably the fastest isdigit()
on any modern cpu.

David

-- 
David Laight: da...@l8s.co.uk