added null checking around token parsing

pull/54/head
alanbjohnston 6 years ago committed by GitHub
parent 0b381b401e
commit 72e12763b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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");

Loading…
Cancel
Save

Powered by TurnKey Linux.