Skip to content

Commit

Permalink
WIP addressing #162, #150
Browse files Browse the repository at this point in the history
  • Loading branch information
cbuahin committed Feb 15, 2024
1 parent 9cad38b commit 91de2fd
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 8 deletions.
21 changes: 19 additions & 2 deletions src/outfile/swmm_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,12 @@ int EXPORT_OUT_API SMO_open(SMO_Handle p_handle, const char *path)
if (p_data == NULL)
return -1;
else {

#ifdef _MSC_VER
strncpy_s(p_data->name, path, MAXFILENAME);
#else
strncpy(p_data->name, path, MAXFILENAME);
#endif

// Attempt to open binary output file for reading only
if ((_fopen(&(p_data->file), path, "rb")) != 0)
Expand Down Expand Up @@ -526,8 +531,15 @@ int EXPORT_OUT_API SMO_getElementName(SMO_Handle p_handle, SMO_elementType type,
*length = p_data->elementNames[idx].length;
*name = newCharArray(*length + 1);
// Writes IDname and an additional null character to name

#ifdef _MSC_VER
strncpy_s(*name, p_data->elementNames[idx].IDname,
(*length + 1) * sizeof(char));
(*length + 1) * sizeof(char));
#else
strncpy(*name, p_data->elementNames[idx].IDname,
(*length + 1) * sizeof(char));
#endif

}
}

Expand Down Expand Up @@ -1036,7 +1048,12 @@ void errorLookup(int errcode, char *dest_msg, int dest_len)
msg = ERR440;
}

strncpy_s(dest_msg, msg, MAXMSG);
#ifdef _MSC_VER
strncpy_s(dest_msg, MAXMSG, msg);
#else
strncpy(est_msg, msg, MAXMSG);
#endif

}

// Local functions:
Expand Down
2 changes: 0 additions & 2 deletions src/solver/consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// Biuld 5.3.0
// - Added MAXHOTSTARTFILES constant to support saving multiple hotstart files
// at different times.
// - Added const for MAX_ERR_MSG_LENGTH to define the maximum length of an error message.
//
//-----------------------------------------------------------------------------

Expand All @@ -29,7 +28,6 @@
#define EOFMARK 0x1A // Use 0x04 for UNIX systems
#define MAXTITLE 3 // Max. # title lines
#define MAXMSG 1024 // Max. # characters in message text
#define MAX_ERR_MSG_LENGTH 256 // Max. # characters in error message text
#define MAXLINE 1024 // Max. # characters per input line
#define MAXFNAME 259 // Max. # characters in file name
#define MAXTOKS 40 // Max. items per line of input
Expand Down
2 changes: 1 addition & 1 deletion src/solver/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "consts.h"
#include "error.h"

char ErrString[MAX_ERR_MSG_LENGTH];
char ErrString[MAXMSG];

char* error_getMsg(int errCode, char* msg)
{
Expand Down
2 changes: 1 addition & 1 deletion src/solver/hotstart.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ int initializeSaveHotstartFile(TFile *hotstartFile)

//=============================================================================

void saveRouting(TFile *hotstartFile)
void saveRouting(TFile *hotstartFile)
//
// Input: hotStartFile = hotstart file to use
// Output: none
Expand Down
3 changes: 1 addition & 2 deletions src/solver/include/swmm5.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ typedef enum {
ERR_API_PROPERTY_VALUE = -999908,
ERR_API_TIME_PERIOD = -999909,
ERR_API_HOTSTART_FILE_OPEN = -999910,
ERR_API_NO_DATA = -999999
} swmm_API_Errors;


Expand All @@ -191,7 +190,7 @@ int DLLEXPORT swmm_close(void);
int DLLEXPORT swmm_getMassBalErr(float *runoffErr, float *flowErr, float *qualErr);
int DLLEXPORT swmm_getVersion(void);
int DLLEXPORT swmm_getError(char *errMsg, int msgLen);
int DLLEXPORT swmm_getErrorFromCode(int error_code, char *outErrMsg[256]);
int DLLEXPORT swmm_getErrorFromCode(int error_code, char **outErrMsg);
int DLLEXPORT swmm_getWarnings(void);

int DLLEXPORT swmm_getCount(int objType);
Expand Down
18 changes: 18 additions & 0 deletions src/solver/swmm5.c
Original file line number Diff line number Diff line change
Expand Up @@ -839,13 +839,31 @@ int DLLEXPORT swmm_getError(char *errMsg, int msgLen)
// --- copy text of last error message into errMsg
if (ErrorCode > 0 && strlen(ErrorMsg) == 0)
error_getMsg(ErrorCode, ErrorMsg);

sstrncpy(errMsg, ErrorMsg, msgLen);

// --- remove leading line feed from errMsg
if ( msgLen > 0 && errMsg[0] == '\n' ) errMsg[0] = ' ';
return ErrorCode;
}

//=============================================================================

int DLLEXPORT swmm_getErrorFromCode(int error_code, char **outErrMsg)
//
// Input: error_code = error code number
// Output: outErrMsg = error message text
// Purpose: retrieves the text of the error message that corresponds to the
// error code number.
{
char err_msg[MAXMSG];
error_getMsg(error_code, err_msg);
sstrncpy(*outErrMsg, err_msg, MAXMSG);

return 0;
}


//=============================================================================

int DLLEXPORT swmm_getCount(int objType)
Expand Down

0 comments on commit 91de2fd

Please sign in to comment.