Skip to content

Incorrect String length after applying WString::replace #6192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
6 tasks done
Hieromon opened this issue Jun 10, 2019 · 2 comments
Closed
6 tasks done

Incorrect String length after applying WString::replace #6192

Hieromon opened this issue Jun 10, 2019 · 2 comments
Assignees
Labels
waiting for feedback Waiting on additional info. If it's not received, the issue may be closed.

Comments

@Hieromon
Copy link

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • I have filled out all fields below.

Platform

  • Hardware: NodeMCU1.0
  • Core Version: 2.5.2 release
  • Development Env: Arduino IDE
  • Operating System: Windows 10

Settings in IDE

  • Module: NodeMCU1.0
  • Flash Mode: dio
  • Flash Size: 4MB/1MB
  • lwip Variant: v2 Lower Memory
  • Reset Method: nodemcu
  • Flash Frequency: 40Mhz
  • CPU Frequency: 160MHz
  • Upload Using: SERIAL
  • Upload Speed: 921600

Problem Description

Depending on the length of WString::replace, replaced string actual length may be 1 byte redundant.
The result of the MCVE sketch will output to the serial monitor as below:

abcde12345⸮
11

The last character will be garbage.

MCVE Sketch

#include <Arduino.h>

void setup() {
  delay(1000);
  Serial.begin(115200);
  String s = "#12345";
  String l = s;
  l.replace("#", "abcde");
  Serial.println(l.c_str());
  Serial.println(l.length());
}

void loop() {
}
@earlephilhower
Copy link
Collaborator

@Hieromon, the String short string optimization was changed recently. Could you try your app with GIT head and see if it fixes things? The test case you've give passes, but I'll see about adding it and some more to the CI suite.

@earlephilhower earlephilhower added the waiting for feedback Waiting on additional info. If it's not received, the issue may be closed. label Jun 10, 2019
@Hieromon
Copy link
Author

@earlephilhower, I confirmed that WString::replace works correctly with the recent GIT with more shorter strings to make sure. They are replaced correctly.
Thank you for your quick response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for feedback Waiting on additional info. If it's not received, the issue may be closed.
Projects
None yet
Development

No branches or pull requests

2 participants