Refactored all the sprintf to use snprintf instead. (#628)

This commit is contained in:
Steve Karg
2024-04-27 12:41:45 -05:00
committed by GitHub
parent 70c54817fd
commit bb276e2431
46 changed files with 308 additions and 272 deletions
+6 -3
View File
@@ -115,8 +115,11 @@ void RS485_Set_Interface(char *ifname)
strupper(ifname);
if (strncmp("COM", ifname, 3) == 0) {
if (strlen(ifname) > 3) {
sprintf(RS485_Port_Name, "\\\\.\\COM%i", atoi(ifname + 3));
fprintf(stdout, "Adjusted interface name to %s\r\n",
snprintf(
RS485_Port_Name, sizeof(RS485_Port_Name), "\\\\.\\COM%i",
atoi(ifname + 3));
fprintf(
stdout, "Adjusted interface name to %s\r\n",
RS485_Port_Name);
}
}
@@ -136,7 +139,7 @@ bool RS485_Interface_Valid(unsigned port_number)
bool status = false;
char ifname[255] = "";
sprintf(ifname, "\\\\.\\COM%u", port_number);
snprintf(ifname, sizeof(ifname), "\\\\.\\COM%u", port_number);
h = CreateFile(
ifname, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if (h == INVALID_HANDLE_VALUE) {