瀏覽代碼

mult: Add missing checks for 0-size parameters

Samuel Thibault 4 年之前
父節點
當前提交
60c6855e0b
共有 1 個文件被更改,包括 30 次插入5 次删除
  1. 30 5
      examples/mult/xgemm.c

+ 30 - 5
examples/mult/xgemm.c

@@ -351,11 +351,6 @@ static void parse_args(int argc, char **argv)
 				fprintf(stderr, "the number of blocks in X cannot be 0!\n");
 				exit(EXIT_FAILURE);
 			}
-			if (nslicesy == 0)
-			{
-				fprintf(stderr, "the number of blocks in Y cannot be 0!\n");
-				exit(EXIT_FAILURE);
-			}
 		}
 
 		else if (strcmp(argv[i], "-nblocksx") == 0)
@@ -395,36 +390,66 @@ static void parse_args(int argc, char **argv)
 		{
 			char *argptr;
 			xdim = strtol(argv[++i], &argptr, 10);
+			if (xdim == 0)
+			{
+				fprintf(stderr, "the X dimension cannot be 0!\n");
+				exit(EXIT_FAILURE);
+			}
 		}
 
 		else if (strcmp(argv[i], "-xy") == 0)
 		{
 			char *argptr;
 			xdim = ydim = strtol(argv[++i], &argptr, 10);
+			if (xdim == 0)
+			{
+				fprintf(stderr, "the XY dimensions cannot be 0!\n");
+				exit(EXIT_FAILURE);
+			}
 		}
 
 		else if (strcmp(argv[i], "-y") == 0)
 		{
 			char *argptr;
 			ydim = strtol(argv[++i], &argptr, 10);
+			if (ydim == 0)
+			{
+				fprintf(stderr, "the Y dimension cannot be 0!\n");
+				exit(EXIT_FAILURE);
+			}
 		}
 
 		else if (strcmp(argv[i], "-z") == 0)
 		{
 			char *argptr;
 			zdim = strtol(argv[++i], &argptr, 10);
+			if (zdim == 0)
+			{
+				fprintf(stderr, "the Z dimension cannot be 0!\n");
+				exit(EXIT_FAILURE);
+			}
 		}
 
 		else if (strcmp(argv[i], "-size") == 0)
 		{
 			char *argptr;
 			xdim = ydim = zdim = strtol(argv[++i], &argptr, 10);
+			if (xdim == 0)
+			{
+				fprintf(stderr, "the size cannot be 0!\n");
+				exit(EXIT_FAILURE);
+			}
 		}
 
 		else if (strcmp(argv[i], "-iter") == 0)
 		{
 			char *argptr;
 			niter = strtol(argv[++i], &argptr, 10);
+			if (niter == 0)
+			{
+				fprintf(stderr, "the number of iterations cannot be 0!\n");
+				exit(EXIT_FAILURE);
+			}
 		}
 
 		else if (strcmp(argv[i], "-nsleeps") == 0)