Merge pull request #3717 from ascillato/patch-1

Code Simplification for Substr
This commit is contained in:
Theo Arends 2018-09-06 19:33:35 +02:00 committed by GitHub
commit b1f0203130
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -143,7 +143,7 @@ char* subStr(char* dest, char* str, const char *delim, int index)
int i;
// Since strtok consumes the first arg, make a copy
strncpy(dest, str, strlen(str));
strncpy(dest, str, strlen(str)+1);
for (i = 1, act = dest; i <= index; i++, act = NULL) {
sub = strtok_r(act, delim, &ptr);
if (sub == NULL) break;

View File

@ -1156,7 +1156,7 @@ boolean KnxCommand()
else if (CMND_KNX_PA == command_code) {
if (XdrvMailbox.data_len) {
if (strstr(XdrvMailbox.data, ".")) { // Process parameter entry
char sub_string[XdrvMailbox.data_len +1];
char sub_string[XdrvMailbox.data_len];
int pa_area = atoi(subStr(sub_string, XdrvMailbox.data, ".", 1));
int pa_line = atoi(subStr(sub_string, XdrvMailbox.data, ".", 2));
@ -1183,7 +1183,7 @@ boolean KnxCommand()
else if ((CMND_KNX_GA == command_code) && (index > 0) && (index <= MAX_KNX_GA)) {
if (XdrvMailbox.data_len) {
if (strstr(XdrvMailbox.data, ",")) { // Process parameter entry
char sub_string[XdrvMailbox.data_len +1];
char sub_string[XdrvMailbox.data_len];
int ga_option = atoi(subStr(sub_string, XdrvMailbox.data, ",", 1));
int ga_area = atoi(subStr(sub_string, XdrvMailbox.data, ",", 2));
@ -1232,7 +1232,7 @@ boolean KnxCommand()
else if ((CMND_KNX_CB == command_code) && (index > 0) && (index <= MAX_KNX_CB)) {
if (XdrvMailbox.data_len) {
if (strstr(XdrvMailbox.data, ",")) { // Process parameter entry
char sub_string[XdrvMailbox.data_len +1];
char sub_string[XdrvMailbox.data_len];
int cb_option = atoi(subStr(sub_string, XdrvMailbox.data, ",", 1));
int cb_area = atoi(subStr(sub_string, XdrvMailbox.data, ",", 2));