diff options
author | Thomas White <taw@physics.org> | 2010-11-29 15:49:22 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2012-02-22 15:27:07 +0100 |
commit | 94584e6626db9b3e828f7ac1da9870f3f9e2fe20 (patch) | |
tree | 167ce4c605b9b4ea2a6599fe2a4dc667768709cf /src | |
parent | 38a944a6c88e320a3fdec41a8d38bd63f72b77ea (diff) |
pattern_sim: Check validity of numbers passed on command line
Diffstat (limited to 'src')
-rw-r--r-- | src/pattern_sim.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/pattern_sim.c b/src/pattern_sim.c index d32f0ae8..b6fcd4e9 100644 --- a/src/pattern_sim.c +++ b/src/pattern_sim.c @@ -199,6 +199,7 @@ int main(int argc, char *argv[]) double *powder; char *intfile = NULL; double *intensities; + char *rval; double *phases; int config_simdetails = 0; int config_nearbragg = 0; @@ -266,7 +267,11 @@ int main(int argc, char *argv[]) break; case 'n' : - n_images = atoi(optarg); + n_images = strtol(optarg, &rval, 10); + if ( *rval != '\0' ) { + ERROR("Invalid number of images.\n"); + return 1; + } break; case 'i' : @@ -302,12 +307,20 @@ int main(int argc, char *argv[]) break; case 3 : - min_size = atof(optarg); + min_size = strtod(optarg, &rval); + if ( *rval != '\0' ) { + ERROR("Invalid minimum size.\n"); + return 1; + } random_size++; break; case 4 : - max_size = atof(optarg); + max_size = strtod(optarg, &rval); + if ( *rval != '\0' ) { + ERROR("Invalid maximum size.\n"); + return 1; + } random_size++; break; |