| To: | xfs@xxxxxxxxxxx |
|---|---|
| Subject: | [PATCH] Init errno before strto* calls. |
| From: | Arkadiusz MiÅkiewicz <arekm@xxxxxxxx> |
| Date: | Sun, 13 Jul 2014 19:38:08 +0200 |
| Cc: | Arkadiusz MiÅkiewicz <arekm@xxxxxxxx> |
| Delivered-to: | xfs@xxxxxxxxxxx |
| Dkim-signature: | v=1; a=rsa-sha256; c=relaxed/relaxed; d=maven.pl; s=maven; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=NI1qXlu5P8wc/XyoMl6j0GKnShL1v0noEKhpMCHGNiE=; b=loMVAgfS9LcxCFdbMsXRF4WkBqzedd/mSI2tKy0qJfJIUOP1+oJvxvVWd3edL+OtSH +Cky3w1CDUPjhpBsYyb3v7f2Ux8oIh3+6m2yi6gJZXLhx0/tBUrFh9tZShNh5AhoVFB5 ny5PehmhxbMdr3aGqJ+0b7lZ3CTgAPYpbiv3k= |
| In-reply-to: | <1405107244-14234-1-git-send-email-arekm@xxxxxxxx> |
| References: | <1405107244-14234-1-git-send-email-arekm@xxxxxxxx> |
Eric Sandeen noted that strtol(3) and friends require errno
initialization. From (fresh) man page:
NOTES
Since strtol() can legitimately return 0, LONG_MAX,
or LONG_MIN (LLONG_MAX or LLONG_MIN for strtoll()) on both
success and failure, the calling program should set errno
to 0 before the call, and then determine if an error
occurred by checking whether errno has a non-zero
value after the call.
So do it.
---
libxcmd/input.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/libxcmd/input.c b/libxcmd/input.c
index 397a124..711b527 100644
--- a/libxcmd/input.c
+++ b/libxcmd/input.c
@@ -153,6 +153,7 @@ cvtnum(
char *sp;
int c;
+ errno = 0;
i = strtoll(s, &sp, 0);
if ((i == LLONG_MIN || i == LLONG_MAX) && errno == ERANGE)
return -1LL;
@@ -239,6 +240,7 @@ cvttime(
unsigned long i;
char *sp;
+ errno = 0;
i = strtoul(s, &sp, 0);
if (i == ULONG_MAX && errno == ERANGE)
return 0;
@@ -348,6 +350,7 @@ prid_from_string(
* Allow either a full numeric or a valid projectname, even
* if it starts with a digit.
*/
+ errno = 0;
prid_long = strtoul(project, &sp, 10);
if (*project != '\0' && *sp == '\0') {
if ((prid_long == ULONG_MAX && errno == ERANGE)
@@ -369,6 +372,7 @@ uid_from_string(
unsigned long uid_long;
char *sp;
+ errno = 0;
uid_long = strtoul(user, &sp, 10);
if (sp != user) {
if ((uid_long == ULONG_MAX && errno == ERANGE)
@@ -390,6 +394,7 @@ gid_from_string(
unsigned long gid_long;
char *sp;
+ errno = 0;
gid_long = strtoul(group, &sp, 10);
if (sp != group) {
if ((gid_long == ULONG_MAX && errno == ERANGE)
--
2.0.1
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | Re: consequences of XFS_IOC_FSSETXATTR on non-empty file?, Ilya Dryomov |
|---|---|
| Next by Date: | Re: consequences of XFS_IOC_FSSETXATTR on non-empty file?, Dave Chinner |
| Previous by Thread: | Re: [PATCH] Catch under/overflow cases in cvtnum() and cvttime()., Eric Sandeen |
| Next by Thread: | Re: [PATCH] Init errno before strto* calls., Dave Chinner |
| Indexes: | [Date] [Thread] [Top] [All Lists] |