Добавлена проверка id

This commit is contained in:
cfif 2025-09-12 10:07:12 +03:00
parent f3bb408e07
commit 541e6b8a01
1 changed files with 16 additions and 10 deletions

View File

@ -110,7 +110,7 @@ int main(int argc, char *argv[]) {
timestamp -= offset_seconds;
}
} else {
printf("Parsing timestamp (UTC) error");
printf("Parsing timestamp (UTC) error\n");
fflush(stdout);
return 1;
}
@ -120,13 +120,13 @@ int main(int argc, char *argv[]) {
printf("timestamp: %u\n", msd.MSD_Data.timestamp);
} else {
printf("Parsing timestamp error");
printf("Parsing timestamp error\n");
fflush(stdout);
return 1;
}
} else {
printf("Parsing JSON timestamp error");
printf("Parsing JSON timestamp error\n");
fflush(stdout);
return 1;
}
@ -185,12 +185,12 @@ int main(int argc, char *argv[]) {
EraGlonassMsdSetPositionValue(&msd, msd.MSD_Data.pos.lon, msd.MSD_Data.pos.lat, 0, 2);
} else {
printf("Parsing coordinate error");
printf("Parsing coordinate error\n");
fflush(stdout);
return 1;
}
} else {
printf("Parsing JSON coordinate error");
printf("Parsing JSON coordinate error\n");
fflush(stdout);
return 1;
}
@ -198,7 +198,7 @@ int main(int argc, char *argv[]) {
if (cJSON_IsString(phoneJS) && (phoneJS->valuestring != NULL)) {
printf("phone (JSON): %s\n", phoneJS->valuestring);
} else {
printf("Parsing JSON phone error");
printf("Parsing JSON phone error\n");
fflush(stdout);
return 1;
}
@ -206,11 +206,17 @@ int main(int argc, char *argv[]) {
if (cJSON_IsString(idJS) && (idJS->valuestring != NULL)) {
printf("id (JSON): %s\n", idJS->valuestring);
char VIN[18] = {0};
char VIN[17] = {0};
memset(VIN, '0', 17);
if (strlen(idJS->valuestring) > sizeof(VIN)) {
printf("Length error id\n");
fflush(stdout);
return 1;
}
memcpy(&VIN[17 - 5], idJS->valuestring, 5);
memset(VIN, '0', sizeof(VIN));
memcpy(&VIN[sizeof(VIN) - strlen(idJS->valuestring)], idJS->valuestring, strlen(idJS->valuestring));
// memcpy(&VIN[5], "1111111111", 10);
EraGlonassMsdSetVIN(&msd, VIN, sizeof(VIN));
@ -218,7 +224,7 @@ int main(int argc, char *argv[]) {
printf("id (VIN): %s\n", VIN);
} else {
printf("Parsing JSON id error");
printf("Parsing JSON id error\n");
fflush(stdout);
return 1;
}