summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Kara <jack@suse.cz>2014-10-01 18:10:40 +0200
committerJan Kara <jack@suse.cz>2014-10-01 18:10:40 +0200
commit663ac451b045b4823d6d633893a5d748c09f42f2 (patch)
tree8d9063ea1af02f43020db3604ecddae278fc31e5
parent072f44cf359a4377b49a9adc003cc4c92fa10be3 (diff)
downloadlinuxquota-663ac451b045b4823d6d633893a5d748c09f42f2.tar.gz
Fix handling of space and inode values
Commit 0214512479e0 (Properly handle signed space and inode values) broke parsing of pure numbers in str2number() so that it would always complain about "Integer overflow while interpreting decimal unit". Fix condition checking for overflow. Also number2str() was buggy and wouldn't guess proper units for negative numbers. Signed-off-by: Jan Kara <jack@suse.cz>
-rw-r--r--quotasys.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/quotasys.c b/quotasys.c
index a5737a8..4b49e0e 100644
--- a/quotasys.c
+++ b/quotasys.c
@@ -459,17 +459,19 @@ void number2str(long long num, char *buf, int format)
int i;
unsigned long long div;
char suffix[8] = " kmgt";
- long long anum = num >= 0 ? num : -num;
- if (format)
- for (i = 4, div = 1000000000000LL; i > 0; i--, div /= 1000)
- if (num >= 100*div) {
- int sign = num != anum ? -1 : 1;
+ if (format) {
+ long long anum = num >= 0 ? num : -num;
+ int sign = num != anum ? -1 : 1;
- sprintf(buf, "%lld%c", (num+div-1) / div * sign,
+ for (i = 4, div = 1000000000000LL; i > 0; i--, div /= 1000)
+ if (anum >= 100*div) {
+ sprintf(buf, "%lld%c",
+ DIV_ROUND_UP(anum, div) * sign,
suffix[i]);
return;
}
+ }
sprintf(buf, "%lld", num);
}
@@ -500,7 +502,7 @@ const char *str2number(const char *string, qsize_t *inodes)
return _("Unknown decimal unit. "
"Valid units are k, m, g, t.");
if (number > QSIZE_MAX / multiple ||
- -number < QSIZE_MAX / multiple)
+ number < -(QSIZE_MAX / multiple))
return _("Integer overflow while interpreting decimal unit.");
*inodes = number * multiple;
return NULL;