1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-03-10 16:58:47 +03:00

cleanup: readable test to check for 32bit overflow

also swap return value 0 - fail, 1 - success.
This commit is contained in:
Zdenek Kabelac 2012-01-19 22:28:06 +01:00
parent 3972bd98fb
commit 9bb210192d

View File

@ -994,10 +994,11 @@ static int xstrtouint32(const char *s, char **p, int base, uint32_t *result)
errno = 0; errno = 0;
ul = strtoul(s, p, base); ul = strtoul(s, p, base);
if (errno || *p == s || (uint32_t) ul != ul) if (errno || *p == s || ul > UINT32_MAX)
return -1; return 0;
*result = ul; *result = ul;
return 0;
return 1;
} }
static int _parse_pes(struct dm_pool *mem, char *c, struct dm_list *pe_ranges, static int _parse_pes(struct dm_pool *mem, char *c, struct dm_list *pe_ranges,
@ -1029,7 +1030,7 @@ static int _parse_pes(struct dm_pool *mem, char *c, struct dm_list *pe_ranges,
/* Start extent given? */ /* Start extent given? */
if (isdigit(*c)) { if (isdigit(*c)) {
if (xstrtouint32(c, &endptr, 10, &start)) if (!xstrtouint32(c, &endptr, 10, &start))
goto error; goto error;
c = endptr; c = endptr;
/* Just one number given? */ /* Just one number given? */
@ -1040,7 +1041,7 @@ static int _parse_pes(struct dm_pool *mem, char *c, struct dm_list *pe_ranges,
if (*c == '-') { if (*c == '-') {
c++; c++;
if (isdigit(*c)) { if (isdigit(*c)) {
if (xstrtouint32(c, &endptr, 10, &end)) if (!xstrtouint32(c, &endptr, 10, &end))
goto error; goto error;
c = endptr; c = endptr;
} }