Adding element id validity checks

This commit is contained in:
Michael Tryby
2019-04-16 16:57:38 -04:00
parent ea8e0439e3
commit 22a7993c8c
9 changed files with 93 additions and 9 deletions

View File

@@ -30,6 +30,8 @@
#include "text.h"
#include "enumstxt.h"
#include "util/cstr_helper.h"
#ifdef _WIN32
#define snprintf _snprintf
#endif
@@ -1731,6 +1733,9 @@ int DLLEXPORT EN_addnode(EN_Project p, char *id, int nodeType)
if (!p->Openflag) return 102;
if (hyd->OpenHflag || qual->OpenQflag) return 262;
// Check if id contains invalid characters
if (!cstr_isvalid(id)) return 250;
// Check if a node with same id already exists
if (EN_getnodeindex(p, id, &i) == 0) return 215;
@@ -2939,6 +2944,9 @@ int DLLEXPORT EN_addlink(EN_Project p, char *id, int linkType,
if (!p->Openflag) return 102;
if (p->hydraul.OpenHflag || p->quality.OpenQflag) return 262;
// Check if id contains invalid characters
if (!cstr_isvalid(id)) return 250;
// Check if a link with same id already exists
if (EN_getlinkindex(p, id, &i) == 0) return 215;
@@ -3951,6 +3959,9 @@ int DLLEXPORT EN_addpattern(EN_Project p, char *id)
if (!p->Openflag) return 102;
if (EN_getpatternindex(p, id, &i) == 0) return 215;
// Check is id name contains invalid characters
if (!cstr_isvalid(id)) return 250;
// Check that id name is not too long
if (strlen(id) > MAXID) return 250;
@@ -4219,6 +4230,9 @@ int DLLEXPORT EN_addcurve(EN_Project p, char *id)
if (!p->Openflag) return 102;
if (EN_getcurveindex(p, id, &i) == 0) return 215;
// Check is id name contains invalid characters
if (!cstr_isvalid(id)) return 250;
// Check that id name is not too long
if (strlen(id) > MAXID) return 250;

View File

@@ -36,11 +36,12 @@ int cstr_duplicate(char **dest, const char *source)
}
bool cstr_validate_id(const char *element_id)
bool cstr_isvalid(const char *element_id)
// Determines if invalid characters are present in an element id string
{
const char *invalid_chars = " \";";
// if invalid char is present a pointer to it is returned else NULL
if (strpbrk(element_id, invalid_chars))
return false;
else

View File

@@ -25,7 +25,7 @@ extern "C" {
int cstr_duplicate(char **dest, const char *source);
bool cstr_validate_id(const char *element_id);
bool cstr_isvalid(const char *element_id);
bool cstr_isnullterm(const char *source);