ソースを参照

Avoid dumb division by zero

Samuel Thibault 8 年 前
コミット
d4dbd8260b
共有1 個のファイルを変更した5 個の追加0 個の削除を含む
  1. 5 0
      examples/cg/cg.c

+ 5 - 0
examples/cg/cg.c

@@ -389,6 +389,11 @@ static void parse_args(int argc, char **argv)
 	        if (strcmp(argv[i], "-maxiter") == 0)
 		{
 			i_max = atoi(argv[++i]);
+			if (i_max <= 0)
+			{
+				FPRINTF(stderr, "the number of iterations must be positive, not %d\n", i_max);
+				exit(EXIT_FAILURE);
+			}
 			continue;
 		}