Skip to content

Commit

Permalink
Fix build warnings on gcc10, mostly stringop-overflow (abd stringop…
Browse files Browse the repository at this point in the history
…-truncation)
  • Loading branch information
jmarrec committed Nov 24, 2020
1 parent d53fb76 commit 2fc152f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
26 changes: 13 additions & 13 deletions third_party/FMI/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ fmiInteger getfmiEPlusVersion(char *fmuWorkingFolder, fmiInteger *sizefmuWorking

// load lib by specifying path to the binaries
if (loadLib(trimfmuWorkingFolder, fmuInstances[_c->index]->modelID, fmuInstances[_c->index])) {
strncpy(fmiVersionNumber, err_msg, strlen(err_msg));
memcpy(fmiVersionNumber, err_msg, strlen(err_msg));
return -1;
}

Expand All @@ -485,7 +485,7 @@ fmiInteger getfmiEPlusVersion(char *fmuWorkingFolder, fmiInteger *sizefmuWorking

// get the modelID of the FMU
verID = fmuInstances[_c->index]->getVersion();
strncpy(fmiVersionNumber, verID, strlen(verID) + 1);
memcpy(fmiVersionNumber, verID, strlen(verID) + 1);

return 0;
}
Expand Down Expand Up @@ -914,7 +914,7 @@ addLibPathCurrentWorkingFolder(char *trimfmuOutputWorkingFolder_wLiB, char *fmuW
trimfmuWorkingFolder = (char *)calloc(*sizefmuWorkingFolder + 1, sizeof(char));

// write fmuWorkingFolder withouth blanks
strncpy(trimfmuWorkingFolder, fmuWorkingFolder, *sizefmuWorkingFolder);
memcpy(trimfmuWorkingFolder, fmuWorkingFolder, *sizefmuWorkingFolder);

// get index value
_c->index = *index;
Expand All @@ -937,18 +937,18 @@ addLibPathCurrentWorkingFolder(char *trimfmuOutputWorkingFolder_wLiB, char *fmuW
// check whether we have folders for Windows 32 and Windows 64 bit
if (bRes_w32 && bRes_w64) {
if (OperSys == 1) {
strncpy(trimfmuOutputWorkingFolder_wLiB, librPath_w32, strlen(librPath_w32));
memcpy(trimfmuOutputWorkingFolder_wLiB, librPath_w32, strlen(librPath_w32));
} else {
strncpy(trimfmuOutputWorkingFolder_wLiB, librPath_w64, strlen(librPath_w64));
memcpy(trimfmuOutputWorkingFolder_wLiB, librPath_w64, strlen(librPath_w64));
}
}
// check whether we just have folder for Windows 32 bit
else if (bRes_w32 && !bRes_w64) {
strncpy(trimfmuOutputWorkingFolder_wLiB, librPath_w32, strlen(librPath_w32));
memcpy(trimfmuOutputWorkingFolder_wLiB, librPath_w32, strlen(librPath_w32));
}
// check whether we just have folder for Windows 64 bit
else if (!bRes_w32 && bRes_w64) {
strncpy(trimfmuOutputWorkingFolder_wLiB, librPath_w64, strlen(librPath_w64));
memcpy(trimfmuOutputWorkingFolder_wLiB, librPath_w64, strlen(librPath_w64));
} else {
printf("Error: FMU does not contain binaries folder for this operating system.");
free(trimfmuWorkingFolder);
Expand Down Expand Up @@ -977,18 +977,18 @@ addLibPathCurrentWorkingFolder(char *trimfmuOutputWorkingFolder_wLiB, char *fmuW
// check whether we have folders for Linux 32 and Linux 64 bit
if (bRes_l32 && bRes_l64) {
if (OperSys == 3) {
strncpy(trimfmuOutputWorkingFolder_wLiB, librPath_l32, strlen(librPath_l32));
memcpy(trimfmuOutputWorkingFolder_wLiB, librPath_l32, strlen(librPath_l32));
} else {
strncpy(trimfmuOutputWorkingFolder_wLiB, librPath_l64, strlen(librPath_l64));
memcpy(trimfmuOutputWorkingFolder_wLiB, librPath_l64, strlen(librPath_l64));
}
}
// check whether we just have folder for Linux 32 bit
else if (bRes_l32 && !bRes_l64) {
strncpy(trimfmuOutputWorkingFolder_wLiB, librPath_l32, strlen(librPath_l32));
memcpy(trimfmuOutputWorkingFolder_wLiB, librPath_l32, strlen(librPath_l32));
}
// check whether we just have folder for Linux 64 bit
else if (!bRes_l32 && bRes_l64) {
strncpy(trimfmuOutputWorkingFolder_wLiB, librPath_l64, strlen(librPath_l64));
memcpy(trimfmuOutputWorkingFolder_wLiB, librPath_l64, strlen(librPath_l64));
} else {
printf("Error: FMU does not contain binaries folder for this operating system.");
free(trimfmuWorkingFolder);
Expand Down Expand Up @@ -1065,10 +1065,10 @@ model_ID_GUID(char *fmuInstanceName, char *fmuWorkingFolder, fmiInteger *sizefmu
fmuInstances[_c->index]->modelDescription = parse(xmlPath);

// Initialize instance Name
fmuInstances[_c->index]->instanceName = (char *)calloc(*fmuInstanceName + 1, sizeof(char));
fmuInstances[_c->index]->instanceName = (char *)calloc(strlen(fmuInstanceName) + 1, sizeof(char));

// write fmu instance Name
strncpy(fmuInstances[_c->index]->instanceName, fmuInstanceName, strlen(fmuInstanceName));
strcpy(fmuInstances[_c->index]->instanceName, fmuInstanceName);

// check whether modelDescription exists or not
if (!fmuInstances[_c->index]->modelDescription) {
Expand Down
11 changes: 6 additions & 5 deletions third_party/FMUParser/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ int callparser(const char *fmuFilNam, const char *tmpPat)
}

length = strlen(fmuFilNam);
tmp = malloc(length * sizeof(char));
tmp = (char *)malloc((length+1) * sizeof(char));
strcpy(tmp, fmuFilNam);

#ifdef _MSC_VER // Command in windows
filNam = malloc(length * sizeof(char));
filNam = (char *)malloc(length * sizeof(char));
if (filNam == NULL) {
printError("Can not allocate memory for filName\n");
free(tmp);
return -1;
}

ext = malloc(length * sizeof(char));
ext = (char *)malloc(length * sizeof(char));
if (ext == NULL) {
printError("Can not allocate memory for ext\n");
free(filNam);
Expand Down Expand Up @@ -247,14 +247,15 @@ int main(int argc, char *argv[])
return -1;
}

objNam = calloc((length + 1), sizeof(char));
objNam = (char *)calloc((length + 1), sizeof(char));
// Copy the fmufilNam without extension as objNam
if (strncpy(objNam, fmuFilNam, length) == NULL) {
if (memcpy(objNam, fmuFilNam, length) == NULL) {
printError("Can not get name \"objNam\" for new folder.\n");
free(objNam);
return -1;
}

// This is pretty useless as calloc will initialize to 0 (which is in effect the null-terminator)
if (strcat(objNam, "\0") == NULL) {
printError("Can not add ending for objNam.\n");
free(objNam);
Expand Down

0 comments on commit 2fc152f

Please sign in to comment.