Bugfix/win32 build warnings (#936)

* Changed win32 port of localtime to use secure OS API functions when compiled with MSVC

* Changed all the sprintf to use snprintf instead in BSC tests to ensure null string endings.
This commit is contained in:
Steve Karg
2025-03-03 10:32:28 -06:00
committed by GitHub
parent b0a26cf2cd
commit 7e725ce028
21 changed files with 317 additions and 275 deletions
+3 -2
View File
@@ -422,8 +422,9 @@ static bool PrettyPrintPropertyValue(
/* eg, property == PROP_LOCAL_DATE
* VTS needs (3-Aug-2011,4) or (8/3/11,4), so we'll use the
* clearer, international form. */
strncpy(short_month, bactext_month_name(value->type.Date.month), 3);
short_month[3] = 0;
snprintf(
short_month, sizeof(short_month), "%s",
bactext_month_name(value->type.Date.month));
fprintf(
stream, "(%u-%3s-%u, %u)", (unsigned)value->type.Date.day,
short_month, (unsigned)value->type.Date.year,
+3 -3
View File
@@ -137,9 +137,9 @@ static void ProcessPT(BACNET_PRIVATE_TRANSFER_DATA *data)
decode_character_string(
&data->serviceParameters[iLen], len_value_type, &bsTemp);
/* Only copy as much as we can accept */
strncpy(
(char *)MyData[(int8_t)cBlockNumber].sMyString,
characterstring_value(&bsTemp), MY_MAX_STR);
snprintf(
(char *)MyData[(int8_t)cBlockNumber].sMyString, MY_MAX_STR,
"%s", characterstring_value(&bsTemp));
/* Make sure it is nul terminated */
MyData[(int8_t)cBlockNumber].sMyString[MY_MAX_STR] = '\0';
/* Signal success */
+3 -4
View File
@@ -76,10 +76,9 @@ static void DecodeBlock(char cBlockNum, uint8_t *pData)
}
iLen += decode_character_string(&pData[iLen], len_value_type, &bsName);
strncpy(
(char *)Response.sMyString, characterstring_value(&bsName), MY_MAX_STR);
Response.sMyString[MY_MAX_STR] = '\0'; /* Make sure it is nul terminated */
snprintf(
(char *)Response.sMyString, MY_MAX_STR, "%s",
characterstring_value(&bsName));
printf("Private Transfer Read Block Response\n");
printf("Data Block: %d\n", (int)cBlockNum);
printf(" First Byte : %d\n", (int)Response.cMyByte1);
+5 -6
View File
@@ -261,9 +261,8 @@ bool read_config(const char *filepath)
fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd) {
struct ifreq ifr;
strncpy(
ifr.ifr_name, current->iface,
sizeof(ifr.ifr_name) - 1);
snprintf(
ifr.ifr_name, sizeof(ifr.ifr_name), "%s", iface);
result = ioctl(fd, SIOCGIFADDR, &ifr);
if (result != -1) {
close(fd);
@@ -468,9 +467,9 @@ bool parse_cmd(int argc, char *argv[])
fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd) {
struct ifreq ifr;
strncpy(
ifr.ifr_name, current->iface,
sizeof(ifr.ifr_name) - 1);
snprintf(
ifr.ifr_name, sizeof(ifr.ifr_name), "%s",
current->iface);
result = ioctl(fd, SIOCGIFADDR, &ifr);
if (result != -1) {
close(fd);