examples: warn on invalid numeric parameters
add ExUtilGet[U]Int / ExUtilGetFloat which print an error message on
parse failure.
fixes issue #219.
(cherry picked from commit 96d43a873a
)
Conflicts:
examples/cwebp.c
examples/dwebp.c
Change-Id: Ie537f5aebd138925bf1a48289b6b5e261b3af2ca
This commit is contained in:
@@ -408,6 +408,7 @@ int main(int argc, char *argv[]) {
|
||||
kParams.use_color_profile = 1;
|
||||
|
||||
for (c = 1; c < argc; ++c) {
|
||||
int parse_error = 0;
|
||||
if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help")) {
|
||||
Help();
|
||||
return 0;
|
||||
@@ -422,7 +423,8 @@ int main(int argc, char *argv[]) {
|
||||
config->options.alpha_dithering_strength = 0;
|
||||
#endif
|
||||
} else if (!strcmp(argv[c], "-dither") && c + 1 < argc) {
|
||||
config->options.dithering_strength = strtol(argv[++c], NULL, 0);
|
||||
config->options.dithering_strength =
|
||||
ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
} else if (!strcmp(argv[c], "-info")) {
|
||||
kParams.print_info = 1;
|
||||
} else if (!strcmp(argv[c], "-version")) {
|
||||
@@ -445,6 +447,11 @@ int main(int argc, char *argv[]) {
|
||||
} else {
|
||||
kParams.file_name = argv[c];
|
||||
}
|
||||
|
||||
if (parse_error) {
|
||||
Help();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (kParams.file_name == NULL) {
|
||||
|
Reference in New Issue
Block a user