return 0;
}
+static int64_t cvtnum(const char *s)
+{
+ char *end;
+ int64_t ret;
+
+ ret = qemu_strtosz(s, &end);
+ if (*end != '\0') {
+ /* Detritus at the end of the string */
+ return -EINVAL;
+ }
+ return ret;
+}
+
static int img_create(int argc, char **argv)
{
int c;
/* Get image size, if specified */
if (optind < argc) {
int64_t sval;
- char *end;
- sval = qemu_strtosz(argv[optind++], &end);
- if (sval < 0 || *end) {
+
+ sval = cvtnum(argv[optind++]);
+ if (sval < 0) {
if (sval == -ERANGE) {
error_report("Image size must be less than 8 EiB!");
} else {
case 'S':
{
int64_t sval;
- char *end;
- sval = qemu_strtosz(optarg, &end);
- if (sval < 0 || *end) {
+
+ sval = cvtnum(optarg);
+ if (sval < 0) {
error_report("Invalid minimum zero buffer size for sparse output specified");
ret = -1;
goto fail_getopt;
break;
case 'o':
{
- char *end;
- errno = 0;
- offset = qemu_strtosz(optarg, &end);
- if (offset < 0|| *end) {
+ offset = cvtnum(optarg);
+ if (offset < 0) {
error_report("Invalid offset specified");
return 1;
}
case 's':
{
int64_t sval;
- char *end;
- sval = qemu_strtosz(optarg, &end);
- if (sval < 0 || sval > INT_MAX || *end) {
+ sval = cvtnum(optarg);
+ if (sval < 0 || sval > INT_MAX) {
error_report("Invalid buffer size specified");
return 1;
}
case 'S':
{
int64_t sval;
- char *end;
- sval = qemu_strtosz(optarg, &end);
- if (sval < 0 || sval > INT_MAX || *end) {
+ sval = cvtnum(optarg);
+ if (sval < 0 || sval > INT_MAX) {
error_report("Invalid step size specified");
return 1;
}
struct DdIo *in, struct DdIo *out,
struct DdInfo *dd)
{
- char *end;
int64_t res;
- res = qemu_strtosz(arg, &end);
+ res = cvtnum(arg);
- if (res <= 0 || res > INT_MAX || *end) {
+ if (res <= 0 || res > INT_MAX) {
error_report("invalid number: '%s'", arg);
return 1;
}
struct DdIo *in, struct DdIo *out,
struct DdInfo *dd)
{
- char *end;
+ dd->count = cvtnum(arg);
- dd->count = qemu_strtosz(arg, &end);
-
- if (dd->count < 0 || *end) {
+ if (dd->count < 0) {
error_report("invalid number: '%s'", arg);
return 1;
}
struct DdIo *in, struct DdIo *out,
struct DdInfo *dd)
{
- char *end;
-
- in->offset = qemu_strtosz(arg, &end);
+ in->offset = cvtnum(arg);
- if (in->offset < 0 || *end) {
+ if (in->offset < 0) {
error_report("invalid number: '%s'", arg);
return 1;
}