fdisk: use strtoul[l] instead of atoi, closes 11176

Couldn't create partitions bigger than 1TB (when using 512 bytes sectors,
on 32 bits architectures).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2018-07-25 12:08:26 +02:00
parent 81de30de05
commit 163e637ffb
2 changed files with 7 additions and 4 deletions

View File

@ -169,9 +169,9 @@ typedef unsigned long long ullong;
* do not support more than 2^32 sectors * do not support more than 2^32 sectors
*/ */
typedef uint32_t sector_t; typedef uint32_t sector_t;
#if UINT_MAX == 4294967295 #if UINT_MAX == 0xffffffff
# define SECT_FMT "" # define SECT_FMT ""
#elif ULONG_MAX == 4294967295 #elif ULONG_MAX == 0xffffffff
# define SECT_FMT "l" # define SECT_FMT "l"
#else #else
# error Cant detect sizeof(uint32_t) # error Cant detect sizeof(uint32_t)
@ -1616,7 +1616,10 @@ read_int(sector_t low, sector_t dflt, sector_t high, sector_t base, const char *
int minus = (*line_ptr == '-'); int minus = (*line_ptr == '-');
int absolute = 0; int absolute = 0;
value = atoi(line_ptr + 1); if (sizeof(value) <= sizeof(long))
value = strtoul(line_ptr + 1, NULL, 10);
else
value = strtoull(line_ptr + 1, NULL, 10);
/* (1) if 2nd char is digit, use_default = 0. /* (1) if 2nd char is digit, use_default = 0.
* (2) move line_ptr to first non-digit. */ * (2) move line_ptr to first non-digit. */

View File

@ -606,7 +606,7 @@ sun_change_sysid(int i, int sys)
"there may destroy your partition table and bootblock.\n" "there may destroy your partition table and bootblock.\n"
"Type YES if you're very sure you would like that partition\n" "Type YES if you're very sure you would like that partition\n"
"tagged with 82 (Linux swap): "); "tagged with 82 (Linux swap): ");
if (strcmp (line_ptr, "YES\n")) if (strcmp(line_ptr, "YES\n"))
return; return;
} }
switch (sys) { switch (sys) {