From 771bdaf069d6f1a4306d0cd321e35d83837a954f Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Fri, 21 Apr 2017 05:07:14 +0000 Subject: [PATCH] Updated C worker program code to properly check return value of scanf() (due to GCC warning). --- c/qrcodegen-worker.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/c/qrcodegen-worker.c b/c/qrcodegen-worker.c index 2e19485..34bf8ba 100644 --- a/c/qrcodegen-worker.c +++ b/c/qrcodegen-worker.c @@ -40,7 +40,8 @@ int main(void) { // Read data length or exit int length; - scanf("%d", &length); + if (scanf("%d", &length) != 1) + return EXIT_FAILURE; if (length == -1) break; @@ -53,14 +54,16 @@ int main(void) { } for (int i = 0; i < length; i++) { int b; - scanf("%d", &b); + if (scanf("%d", &b) != 1) + return EXIT_FAILURE; data[i] = (uint8_t)b; isAscii &= 0 < b && b < 128; } // Read encoding parameters int errCorLvl, minVersion, maxVersion, mask, boostEcl; - scanf("%d %d %d %d %d", &errCorLvl, &minVersion, &maxVersion, &mask, &boostEcl); + if (scanf("%d %d %d %d %d", &errCorLvl, &minVersion, &maxVersion, &mask, &boostEcl) != 5) + return EXIT_FAILURE; // Allocate memory for QR Code int bufferLen = qrcodegen_BUFFER_LEN_FOR_VERSION(maxVersion);