瀏覽代碼

BUG: the return value of scanf should not be ignored

Amitha Perera 17 年之前
父節點
當前提交
47aa926523
共有 1 個文件被更改,包括 5 次插入1 次删除
  1. 5 1
      Templates/TestDriver.cxx.in

+ 5 - 1
Templates/TestDriver.cxx.in

@@ -70,7 +70,11 @@ int main(int ac, char *av[])
     printf("To run a test, enter the test number: ");
     fflush(stdout);
     testNum = 0;
-    scanf("%d", &testNum);
+    if( scanf("%d", &testNum) != 1 )
+      {
+      printf("Couldn't parse that input as a number\n");
+      return -1;
+      }
     if (testNum >= NumTests)
       {
       printf("%3d is an invalid test number.\n", testNum);