Skip to content

Commit 34441cc

Browse files
authored
Fixed: comparing functions throws exception when parameter is missing (#18)
1 parent dcaa7ea commit 34441cc

File tree

1 file changed

+43
-7
lines changed

1 file changed

+43
-7
lines changed

src/CmdParser.hpp

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,20 @@ class CmdParser
101101
*
102102
* @param idx Number of param to get
103103
* @param value String to compare
104-
* @return TRUE is equal
104+
* @return TRUE if equal
105105
*/
106106
bool equalCmdParam(uint16_t idx, CmdParserString value)
107107
{
108-
if (strcasecmp(this->getCmdParam(idx), value) == 0) {
108+
char *param = this->getCmdParam(idx);
109+
110+
if (param == NULL) {
111+
if (value == NULL) {
112+
return true;
113+
}
114+
return false;
115+
}
116+
117+
if (strcasecmp(param, value) == 0) {
109118
return true;
110119
}
111120

@@ -116,7 +125,7 @@ class CmdParser
116125
* Check if command equal with value case sensitive.
117126
*
118127
* @param value String to compare
119-
* @return TRUE is equal
128+
* @return TRUE if equal
120129
*/
121130
bool equalCommand(CmdParserString value)
122131
{
@@ -128,11 +137,20 @@ class CmdParser
128137
*
129138
* @param key Key store in SRAM for search in cmd
130139
* @param value String to compare in PROGMEM
131-
* @return TRUE is equal
140+
* @return TRUE if equal
132141
*/
133142
bool equalValueFromKey(CmdParserString key, CmdParserString value)
134143
{
135-
if (strcasecmp(this->getValueFromKey(key, false), value) == 0) {
144+
char *param = this->getValueFromKey(key, false);
145+
146+
if (param == NULL) {
147+
if (value == NULL) {
148+
return true;
149+
}
150+
return false;
151+
}
152+
153+
if (strcasecmp(param, value) == 0) {
136154
return true;
137155
}
138156

@@ -154,7 +172,16 @@ class CmdParser
154172
*/
155173
bool equalValueFromKey_P(CmdParserString key, CmdParserString value)
156174
{
157-
if (strcasecmp_P(this->getValueFromKey(key, true), value) == 0) {
175+
char *param = this->getValueFromKey(key, true);
176+
177+
if (param == NULL) {
178+
if (value == NULL) {
179+
return true;
180+
}
181+
return false;
182+
}
183+
184+
if (strcasecmp_P(param, value) == 0) {
158185
return true;
159186
}
160187

@@ -166,7 +193,16 @@ class CmdParser
166193
*/
167194
bool equalCmdParam_P(uint16_t idx, CmdParserString_P value)
168195
{
169-
if (strcasecmp_P(this->getCmdParam(idx), value) == 0) {
196+
char *param = this->getCmdParam(idx);
197+
198+
if (param == NULL) {
199+
if (value == NULL) {
200+
return true;
201+
}
202+
return false;
203+
}
204+
205+
if (strcasecmp_P(param, value) == 0) {
170206
return true;
171207
}
172208

0 commit comments

Comments
 (0)