mkswap: more robust strtoull() usage
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
69cc2ec061
commit
20543e618a
|
@ -559,13 +559,18 @@ main(int argc, char ** argv) {
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
if (block_count) {
|
if (block_count) {
|
||||||
/* this silly user specified the number of blocks
|
/* this silly user specified the number of blocks explicitly */
|
||||||
explicitly */
|
char *tmp = NULL;
|
||||||
char *tmp;
|
long long blks;
|
||||||
int blocks_per_page = pagesize/1024;
|
|
||||||
PAGES = strtoull(block_count,&tmp,0)/blocks_per_page;
|
errno = 0;
|
||||||
if (*tmp)
|
blks = strtoll(block_count, &tmp, 0);
|
||||||
|
if ((tmp && *tmp) ||
|
||||||
|
(errno != 0 && (blks == ULLONG_MAX || blks == 0)) ||
|
||||||
|
blks < 0)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
|
PAGES = blks / (pagesize / 1024);
|
||||||
}
|
}
|
||||||
sz = get_size(device_name);
|
sz = get_size(device_name);
|
||||||
if (!PAGES) {
|
if (!PAGES) {
|
||||||
|
|
Loading…
Reference in New Issue