examples/bitbang_cbus.c: Check return value of fgets()
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Mon, 24 Aug 2020 17:45:41 +0000 (19:45 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Mon, 24 Aug 2020 17:45:41 +0000 (19:45 +0200)
examples/bitbang_cbus.c

index b902b50..359097e 100644 (file)
@@ -60,8 +60,9 @@ int main(void)
     while (1)
     {
         // Set bitmask from input
-        fgets(input, sizeof(input) - 1, stdin);
-        if (input[0] == '\n') break;
+        char *s = fgets(input, sizeof(input) - 1, stdin);
+        if (s == NULL || input[0] == '\n')
+            break;
         bitmask = strtol(input, NULL, 0);
         printf("Using bitmask 0x%02x\n", bitmask);
         f = ftdi_set_bitmode(ftdi, bitmask, BITMODE_CBUS);