Merge pull request #472 from makusuko/fix-rules-label
Fix NULL pointer error if rules label is missing
This commit is contained in:
5
LICENSE
5
LICENSE
@@ -1,11 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
Works are copyright (c) 2018 their respective AUTHORS,
|
|
||||||
unless such work is in the Public Domain (again, see AUTHORS)
|
|
||||||
=======
|
|
||||||
Copyright (c) 2017 Open Water Analytics
|
Copyright (c) 2017 Open Water Analytics
|
||||||
>>>>>>> master
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
34
src/rules.c
34
src/rules.c
@@ -110,6 +110,10 @@ void initrules(Project *pr)
|
|||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
{
|
{
|
||||||
pr->rules.RuleState = r_PRIORITY;
|
pr->rules.RuleState = r_PRIORITY;
|
||||||
|
pr->rules.LastPremise = NULL;
|
||||||
|
pr->rules.LastThenAction = NULL;
|
||||||
|
pr->rules.LastElseAction = NULL;
|
||||||
|
pr->rules.ActionList = NULL;
|
||||||
pr->network.Rule = NULL;
|
pr->network.Rule = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,8 +173,14 @@ void freerules(Project *pr)
|
|||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
// Already freed
|
||||||
|
if (pr->network.Rule == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
for (i = 1; i <= pr->network.Nrules; i++) clearrule(pr, i);
|
for (i = 1; i <= pr->network.Nrules; i++) clearrule(pr, i);
|
||||||
free(pr->network.Rule);
|
free(pr->network.Rule);
|
||||||
|
pr->network.Rule = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ruledata(Project *pr)
|
int ruledata(Project *pr)
|
||||||
@@ -199,6 +209,12 @@ int ruledata(Project *pr)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case r_RULE:
|
case r_RULE:
|
||||||
|
// Missing the rule label
|
||||||
|
if (parser->Ntokens != 2)
|
||||||
|
{
|
||||||
|
err = 201;
|
||||||
|
break;
|
||||||
|
}
|
||||||
net->Nrules++;
|
net->Nrules++;
|
||||||
newrule(pr);
|
newrule(pr);
|
||||||
rules->RuleState = r_RULE;
|
rules->RuleState = r_RULE;
|
||||||
@@ -302,24 +318,24 @@ void ruleerrmsg(Project *pr)
|
|||||||
// Get label of rule being parsed
|
// Get label of rule being parsed
|
||||||
if (net->Nrules > 0)
|
if (net->Nrules > 0)
|
||||||
{
|
{
|
||||||
strcpy(label, t_RULE);
|
strncpy(label, t_RULE, MAXMSG);
|
||||||
strcat(label, " ");
|
strncat(label, " ", MAXMSG);
|
||||||
strcat(label, net->Rule[net->Nrules].label);
|
strncat(label, net->Rule[net->Nrules].label, MAXMSG);
|
||||||
}
|
}
|
||||||
else strcpy(label, t_RULES_SECT);
|
else strncpy(label, t_RULES_SECT, MAXMSG);
|
||||||
|
|
||||||
// Write rule label and error message to status report
|
// Write rule label and error message to status report
|
||||||
sprintf(pr->Msg, "%s", msg);
|
snprintf(pr->Msg, MAXMSG, "%s", msg);
|
||||||
strcat(pr->Msg, label);
|
strncat(pr->Msg, label, MAXMSG);
|
||||||
strcat(pr->Msg, ":");
|
strncat(pr->Msg, ":", MAXMSG);
|
||||||
writeline(pr, pr->Msg);
|
writeline(pr, pr->Msg);
|
||||||
|
|
||||||
// Write text of rule clause being parsed to status report
|
// Write text of rule clause being parsed to status report
|
||||||
strcpy(msg, Tok[0]);
|
strcpy(msg, Tok[0]);
|
||||||
for (i = 1; i < parser->Ntokens; i++)
|
for (i = 1; i < parser->Ntokens; i++)
|
||||||
{
|
{
|
||||||
strcat(msg, " ");
|
strncat(msg, " ", MAXLINE);
|
||||||
strcat(msg, Tok[i]);
|
strncat(msg, Tok[i], MAXLINE);
|
||||||
}
|
}
|
||||||
writeline(pr, msg);
|
writeline(pr, msg);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user