Teensy 4.0 library issues

JohnP

New member
I believe I have found a couple of issues with the Teensy 4.0 operation.

1) We had some code that stripped leading space from a string. If the string consisted of only spaces, it would eventually get to a null string. The code is this:


String command=inputBuffer.substring(url_start,url_end);

while (command[0]==' ') command=command.substring(1);

On the Teensy 3.2, if the string that was passed in is only spaces, eventually this leads to command becoming the null string. On the Teensy 4.0, this crashes and it never reaches the next line of code. The workaround is to replace that line with this:

while (command[0]==' ') { if (command.length() > 1) { command=command.substring(1);} else {command = ""; } }

which works fine. But every other Arduino compiler/library combination accepts the first one and does not cause a failure.

2) Returning null string from a string function causes a crash.

The function:

String WebServer::arg(String id) {
return "";
}

never returns to the calling function. If you add any characters inside the quote marks, it does return that value to the calling routine. Again this is different from every other Arduino compiler/ library operation that does return the null string to the calling routing.

John Petterson
john@petterson.me
 
There is a STRING edit in TD 1.54 regarding NULL return.

Please see that Annoucement forum thread for the latest TD 1.54 Beta 6.

Read the notes and see if it may apply and perhaps install and use that version to test.

In any case if there is an issue it would be against that Build that any fix would be applied.
 
It looks like quite ineffective way to remove trailing spaces from the string.

Better way would be counting number of spaces and then simply: command.remove(0, space_count); - it also avoids that NULL problem in unfixed version of WString as it avoids copy assigment operator with empty string.

Current way utilizes lots and lots of memory allocations/dealocations (as it can't be moved).
Btw there is also std::string available and it also has a short string optimization (if I recall it correctly, strings under 16B - 15characters + nul terminal character), that means short strings are stored directly in the object without any heap allocation at all.
 
Back
Top