aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2010-11-29 15:49:22 +0100
committerThomas White <taw@physics.org>2012-02-22 15:27:07 +0100
commit94584e6626db9b3e828f7ac1da9870f3f9e2fe20 (patch)
tree167ce4c605b9b4ea2a6599fe2a4dc667768709cf
parent38a944a6c88e320a3fdec41a8d38bd63f72b77ea (diff)
pattern_sim: Check validity of numbers passed on command line
-rw-r--r--src/pattern_sim.c19
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;