Skip to content
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

Fixed the String::lastIndexOf bug #9003

Merged
merged 3 commits into from
Dec 20, 2023

Conversation

a1ext
Copy link
Contributor

@a1ext a1ext commented Dec 14, 2023

The String::lastIndexOf incorrectly finds character \0 behind the string size, so extra check was added.

Description of Change

This pull request fixes the bug in int String::lastIndexOf(char ch, unsigned int fromIndex) const function. The bug itself
is that if the character we are searching is \0 this function returns an index behind bounds of the string itself.
For example the following code prints that it found it at 4th position (points after the end of the actual string):

String test = "test";
int p = test.lastIndexOf('\0');
USBSerial.printf("lastIndexOf: %d\n", p);

output:

lastIndexOf: 4

but it must be -1 because there is no \0 character inside the string itself.

Tests scenarios

I've tested the code on M5Stack-CoreS3 hardware, Arduino-esp32 core v 3.20011.230801 (framework-arduinoespressif32)

Test case when it is fixed:

String test = "test";
int p = test.lastIndexOf('\0');
assert(p == -1);

@CLAassistant
Copy link

CLAassistant commented Dec 14, 2023

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

github-actions bot commented Dec 14, 2023

Messages
📖 You might consider squashing your 3 commits (simplifying branch history).

👋 Hello a1ext, we appreciate your contribution to this project!


Click to see more instructions ...


This automated output is generated by the PR linter DangerJS, which checks if your Pull Request meets the project's requirements and helps you fix potential issues.

DangerJS is triggered with each push event to a Pull Request and modify the contents of this comment.

Please consider the following:
- Danger mainly focuses on the PR structure and formatting and can't understand the meaning behind your code or changes.
- Danger is not a substitute for human code reviews; it's still important to request a code review from your colleagues.
- Addressing info messages (📖) is strongly recommended; they're less critical but valuable.
- To manually retry these Danger checks, please navigate to the Actions tab and re-run last Danger workflow.

Review and merge process you can expect ...


We do welcome contributions in the form of bug reports, feature requests and pull requests.

1. An internal issue has been created for the PR, we assign it to the relevant engineer.
2. They review the PR and either approve it or ask you for changes or clarifications.
3. Once the GitHub PR is approved we do the final review, collect approvals from core owners and make sure all the automated tests are passing.
- At this point we may do some adjustments to the proposed change, or extend it by adding tests or documentation.
4. If the change is approved and passes the tests it is merged into the default branch.

Generated by 🚫 dangerJS against 66b3484

Copy link
Member

@P-R-O-C-H-Y P-R-O-C-H-Y left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@VojtechBartoska VojtechBartoska added this to the 3.0.0-RC1 milestone Dec 20, 2023
@VojtechBartoska
Copy link
Collaborator

@VojtechBartoska VojtechBartoska added the Status: Pending Merge Pull Request is ready to be merged label Dec 20, 2023
@lucasssvaz lucasssvaz added the Type: Bug 🐛 All bugs label Dec 20, 2023
@me-no-dev me-no-dev merged commit f6e12eb into espressif:master Dec 20, 2023
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Pending Merge Pull Request is ready to be merged Type: Bug 🐛 All bugs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants