Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: Teensy 4.0 library issues

  1. #1
    Junior Member
    Join Date
    Nov 2020
    Posts
    1

    Teensy 4.0 library issues

    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

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    13,495
    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.

  3. #3
    Junior Member
    Join Date
    Oct 2020
    Posts
    9
    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.

  4. #4
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    6,366

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •