diff options
author | Brian Norris <computersforpeace@gmail.com> | 2015-08-31 14:34:02 -0700 |
---|---|---|
committer | Brian Norris <computersforpeace@gmail.com> | 2015-11-11 14:05:36 -0800 |
commit | c1bda1eaf2c80388fdd959a41d9da18d437d019e (patch) | |
tree | ceeaaf8d95f8dfced79439eb532f90c77c3cec75 /flash_unlock.c | |
parent | 4e2a2a22676eb8d3622c357ac6867d815500438f (diff) |
flash_{un,}lock: improve strtol() error handling
Use the simple_* helpers to improve error checking.
Also fixup brace style at the same time.
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Diffstat (limited to 'flash_unlock.c')
-rw-r--r-- | flash_unlock.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/flash_unlock.c b/flash_unlock.c index 6443605..7a7a773 100644 --- a/flash_unlock.c +++ b/flash_unlock.c @@ -147,8 +147,8 @@ int main(int argc, char *argv[]) int fd, request; struct mtd_info_user mtdInfo; struct erase_info_user mtdLockInfo; - int count; - int ret; + long count; + int ret = 0; process_args(argc, argv); @@ -161,22 +161,28 @@ int main(int argc, char *argv[]) sys_errmsg_die("could not get mtd info: %s", dev); /* Make sure user options are valid */ - if (offs_s) - mtdLockInfo.start = strtol(offs_s, NULL, 0); - else + if (offs_s) { + mtdLockInfo.start = simple_strtol(offs_s, &ret); + if (ret) + errmsg_die("bad offset"); + } else { mtdLockInfo.start = 0; + } if (mtdLockInfo.start > mtdInfo.size) errmsg_die("%#x is beyond device size %#x", mtdLockInfo.start, mtdInfo.size); if (count_s) { - count = strtol(count_s, NULL, 0); + count = simple_strtol(count_s, &ret); + if (ret) + errmsg_die("bad count"); if (count == -1) mtdLockInfo.length = mtdInfo.size; else mtdLockInfo.length = mtdInfo.erasesize * count; - } else + } else { mtdLockInfo.length = mtdInfo.size; + } if (mtdLockInfo.start + mtdLockInfo.length > mtdInfo.size) errmsg_die("range is more than device supports: %#x + %#x > %#x", mtdLockInfo.start, mtdLockInfo.length, mtdInfo.size); |