Commits

iru  committed c49d933

Add checking of command line arguments.

  • Participants
  • Parent commits b788f73

Comments (0)

Files changed (1)

 {
 	void *p;
 	p = malloc(size);
-	if(!p){
+	if(p == NULL){
 		fprintf(stderr, "out of memory\n");
 		exit(1);
 	}
 	return p;
 }
 
-double
-xrand(void)
-{
-	struct timeval tv;
-
-	gettimeofday(&tv, NULL);
-	srand(tv.tv_usec);
-	return (double)rand() / (double)(RAND_MAX+1.0);
-}
-
 Partsys*
 newpartsys(int n, Vect *grav, float dt)
 {
 	}
 
 	n = atoi(argv[1]);
+	if(n < 1){
+		fprintf(stderr, "nparts must be positive\n");
+		exit(1);
+	}
 	k = atof(argv[2]);
 	if(k < 0 || k > 1){
 		fprintf(stderr, "k must be in [0,1]\n");
 		exit(1);
 	}
+
 	sys = newpartsys(n, &grav, 0.1);
 	if(!sys)
 		exit(1);