From 96c7e283c0f135a8eea2e973a532b5d8e50bb0c8 Mon Sep 17 00:00:00 2001 From: Darryl Miles Date: Mon, 30 Sep 2024 01:48:58 +0100 Subject: [PATCH] gcr/gcrDebug.c: Incorrect return-value check for a 'scanf'-like function Fix code scanning alert no. 137: Incorrect return-value check for a 'scanf'-like function (#9) * Create codeql.yml * Fix code scanning alert no. 137: Incorrect return-value check for a 'scanf'-like function Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- gcr/gcrDebug.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gcr/gcrDebug.c b/gcr/gcrDebug.c index a0fad0e1..16a5bbcb 100644 --- a/gcr/gcrDebug.c +++ b/gcr/gcrDebug.c @@ -978,8 +978,12 @@ gcrShowMap(ch) while (1) { TxPrintf("Field selector (0 terminates): "); - if(!scanf("%d", &field)) /*typed something funny*/ + if(scanf("%d", &field) != 1) /*typed something funny or EOF*/ { + if (feof(stdin)) { + TxPrintf("End of input detected. Terminating.\n"); + return; + } TxPrintf("Bad input. Legal responses are\n"); TxPrintf(" GCRBLKM 1\n"); TxPrintf(" GCRBLKP 2\n");