From 72e12763b0669b9ced5474e442132ae25188366f Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 29 Aug 2020 11:02:40 -0400 Subject: [PATCH] added null checking around token parsing --- afsk/main.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index a0bc0f8d..9d7ac303 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1079,15 +1079,24 @@ if (firstTime != ON) token = strtok(cmdbuffer, space); float voltage[9], current[9]; - + memset(voltage, 0, 9*sizeof(voltage[0])); + memset(current, 0, 9*sizeof(current[0])); + for (count1 = 0; count1 < 8; count1++) { + if (token != NULL) + { voltage[count1] = atof(token); - printf("voltage: %f ", voltage[count1]); - token = strtok(NULL, space); - current[count1] = atof(token); - printf("current: %f\n", current[count1]); - token = strtok(NULL, space); + printf("voltage: %f ", voltage[count1]); + + token = strtok(NULL, space); + if (token != NULL) + { + current[count1] = atof(token); + printf("current: %f\n", current[count1]); + token = strtok(NULL, space); + } + } } printf("\n");