NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
lib/49640: Improve example of strto[iu](3)
>Number: 49640
>Category: lib
>Synopsis: Improve example of strto[iu](3)
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: lib-bug-people
>State: open
>Class: doc-bug
>Submitter-Id: net
>Arrival-Date: Wed Feb 04 23:20:00 +0000 2015
>Originator: Kamil Rytarowski
>Release: current
>Organization:
>Environment:
N/A
>Description:
In the example usage of strtoi(3) and strtou(3) there is reused warn(3), which takes a value of errno. errno for the string conversion calls is guaranteed to be unchanged so warn(3) prints trash.
>How-To-Repeat:
man strtoi
man strtou
>Fix:
diff --git a/libc/stdlib/strtol.3 b/libc/stdlib/strtol.3
index 5eb586b..a1f3834 100644
--- a/libc/stdlib/strtol.3
+++ b/libc/stdlib/strtol.3
@@ -243,8 +243,8 @@ 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",
- buf, lval);
+ warnx("conversion of `%s' to a number failed, using %jd: %s",
+ buf, lval, strerror(3));
.Ed
.Pp
This will always return a number in
diff --git a/libc/stdlib/strtoul.3 b/libc/stdlib/strtoul.3
index ee0ebde..d3a59fa 100644
--- a/libc/stdlib/strtoul.3
+++ b/libc/stdlib/strtoul.3
@@ -240,8 +240,8 @@ 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",
- buf, lval);
+ warnx("conversion of `%s' to a number failed, using %ju: %s",
+ buf, lval, strerror(e));
.Ed
.Pp
This will always return a number in
Home |
Main Index |
Thread Index |
Old Index