Not able to split string into 2 char I am trying to split an incoming string into 2 integer values since I have to control 2 dc motors with it. The processor is node MCU and I get following error:-

Com Port Reading:-

WiFi connected
Received: "84+62"
"84+62"

Soft WDT reset

&gt;&gt;&gt;stack&gt;&gt;&gt;

ctx: cont
sp: 3ffffd90 end: 3fffffc0 offset: 01b0
3fffff40:  2b343822 00223236 3ffee70c 40204148  
3fffff50:  3ffe85ee 3ffee6d8 3ffee70c 402043c5  
3fffff60:  3ffe85dc 3ffee70c 3ffee6d8 402043c5  
3fffff70:  3ffe85f0 3ffee69c 00000000 00000001  
3fffff80:  00000000 40200038 3ffefca4 0000000f  
3fffff90:  00000007 00000000 00000001 402048f9  
3fffffa0:  3fffdad0 00000000 3ffee744 40204984  
3fffffb0:  feefeffe feefeffe 3ffe851c 401009a5  
&lt;&lt;&lt;stack&lt;&lt;&lt;

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v951aeffa
~ld


Code:-

if (msg.length() &gt; 0) {
        Serial.print("Received: "); Serial.println(msg);
        char charBuf[50];
        msg.toCharArray(charBuf, 50);
        Serial.println(charBuf);

        char left[3] = {};
        char right[3] = {};
        int n = 0;

        while (charBuf != 0) {
          for (int i = 0; i &lt; strlen(charBuf); i ++) {
            if (charBuf[i] != '+') {
              left[n] += charBuf[i];
              n++;
            }
            else {
              n = 0;
              break;
            }
            right[n] += charBuf[i];
            n++;
          }
        }
        Serial.println("Left Motor: "); Serial.print(left);
        Serial.println("Right Motor: "); Serial.print(right);

    }


My desired result is following:-

Left Motor: 84
Right Motor: 62


So what changes I need to make?
You get this memory leak because you overflow the variable right. This does not happen in the for loop itself even though this could be implemented more straight forward. But it's the while loop that doesn't come to an end (charBuf doesn't change and will not become 0) and in the second iteration n will be 1 initially (due to n++ at the end of the for loop). That causes the overflow at right[n] += charBuf[i];.

So: remove the while loop (and use strtok()).