| To: | xfs@xxxxxxxxxxx |
|---|---|
| Subject: | [PATCH] Detect strto* failures based on errno. |
| From: | Arkadiusz MiÅkiewicz <arekm@xxxxxxxx> |
| Date: | Mon, 14 Jul 2014 09:56:59 +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 :mime-version:content-type:content-transfer-encoding; bh=guzcXRPvB6lSLy7gcitWyhZTHHHfMSWRIlQgpcUPCG0=; b=KQFTi03S77QHzZBTHVaywqYLQTFJcUxBT42DSkENJBu7OjyoC/V4jYPCpBMXWtRRfl Dj6vrZMveFbleuqjAs1lJpLBDoseAV5mV53MIKqhH3huhxMf5MFdAhQFQyINp3nebjTL krT2L4zXgqDupz9/BxkGfj6Nx0Ajuw3UdDjZU= |
| In-reply-to: | <20140713230406.GE22339@dastard> |
| References: | <20140713230406.GE22339@dastard> |
Code was testing for ERANGE errno only in some places. In other places
it didn't do any errno checking at all.
Unify strto* result testing by treating any non zero errno as failure.
Signed-off-by: Arkadiusz MiÅkiewicz <arekm@xxxxxxxx>
---
libxcmd/input.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/libxcmd/input.c b/libxcmd/input.c
index c06b5b8..d72dff3 100644
--- a/libxcmd/input.c
+++ b/libxcmd/input.c
@@ -153,8 +153,9 @@ cvtnum(
char *sp;
int c;
+ errno = 0;
i = strtoll(s, &sp, 0);
- if (i == 0 && sp == s)
+ if (errno || (i == 0 && sp == s))
return -1LL;
if (*sp == '\0')
return i;
@@ -237,8 +238,9 @@ cvttime(
unsigned long i;
char *sp;
+ errno = 0;
i = strtoul(s, &sp, 0);
- if (i == 0 && sp == s)
+ if (errno || (i == 0 && sp == s))
return 0;
if (*sp == '\0')
return i;
@@ -344,10 +346,10 @@ 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)
- || (prid_long > (prid_t)-1))
+ if (errno || (prid_long > (prid_t)-1))
return -1;
return (prid_t)prid_long;
}
@@ -365,10 +367,10 @@ 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)
- || (uid_long > (uid_t)-1))
+ if (errno || (uid_long > (uid_t)-1))
return -1;
return (uid_t)uid_long;
}
@@ -386,10 +388,10 @@ 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)
- || (gid_long > (gid_t)-1))
+ if (errno || (gid_long > (gid_t)-1))
return -1;
return (gid_t)gid_long;
}
--
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: symlink loop for /lib64/libhandle.so, Jan ÅulÃk |
| Previous by Thread: | Re: [PATCH] Init errno before strto* calls., Dave Chinner |
| Next by Thread: | Re: [PATCH] Detect strto* failures based on errno., Dave Chinner |
| Indexes: | [Date] [Thread] [Top] [All Lists] |