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

tools/bugpoint/ToolRunner.cpp:386: bad for loop ? #31485

Closed
llvmbot opened this issue Mar 4, 2017 · 6 comments
Closed

tools/bugpoint/ToolRunner.cpp:386: bad for loop ? #31485

llvmbot opened this issue Mar 4, 2017 · 6 comments
Labels
bugzilla Issues migrated from bugzilla invalid Resolved as invalid, i.e. not a bug tools:bugpoint

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Mar 4, 2017

Bugzilla Link 32137
Resolution INVALID
Resolved on Apr 13, 2019 07:18
Version trunk
OS Linux
Reporter LLVM Bugzilla Contributor
CC @adibiagio,@the-edd,@RKSimon

Extended Description

tools/bugpoint/ToolRunner.cpp:386]: (error) When Pos==CommandLine.size(), CommandLine[Pos] is out of bounds.

Source code is

for (std::size_t Pos = 0u; Pos <= CommandLine.size(); ++Pos) {
if ('\' == CommandLine[Pos]) {

Maybe better code

for (std::size_t Pos = 0u; Pos < CommandLine.size(); ++Pos) {
if ('\' == CommandLine[Pos]) {

@adibiagio
Copy link
Collaborator

Hi David,

Thanks for reporting this issue.
Owen just uploaded a patch for it here: https://reviews.llvm.org/D30704

Could you please verify if that fixes your issue?

Thanks,
Andrea

@llvmbot
Copy link
Collaborator Author

llvmbot commented Mar 7, 2017

Could you please verify if that fixes your issue?

No it doesn't. Proposed solution misses the point.

For loop still has inclusive upper and lower limits,
which is IMHO a newbie off by one error.

Every C programmer should know that lower limits are inclusive and
upper limits are exclusive.

Suggest have another look at my proposed solution.

@adibiagio
Copy link
Collaborator

Could you please verify if that fixes your issue?

No it doesn't. Proposed solution misses the point.

For loop still has inclusive upper and lower limits,
which is IMHO a newbie off by one error.

Every C programmer should know that lower limits are inclusive and
upper limits are exclusive.

Suggest have another look at my proposed solution.

If you think that his patch is not okay, then perhaps leave comment on the code review. I posted that message on Owen's behalf since he didn't have a bugzilla account and he had to leave the office.

@the-edd
Copy link

the-edd commented Mar 13, 2017

I'm writing this on Owen's behalf. He requested a bugzilla login a few days ago, but it hasn't yet been created.


Hi David,

Thanks for looking into this revision, after looking further into the issue you describe I have found that a fix is not required.

Unfortunately your suggested change will break the algorithm. The final pass in the loop is required so a remaining token can be pushed into the Args vector (line 392 to 406). As the bug regards access using the [] operator I uploaded a new revision, however I have abandoned this change due to the following in the C++11 standard:

21.4.5 basic_string element access
operator[](size_type pos);
Requires: pos <= size().
Returns: *(begin() + pos) if pos < size(), otherwise a reference to an object of type T with value charT(); the referenced value shall not be modified.

This means that the operator[str.size()] will return '\0'

Looking at your first post it appears to include an error message. Could you please describe the method used to find this?

Thanks,

Owen

@llvmbot
Copy link
Collaborator Author

llvmbot commented Mar 14, 2017

This means that the operator[str.size()] will return '\0'

News to me. Thanks for the information.

Looking at your first post it appears to include an error message. Could you
please describe the method used to find this?

I used cppcheck, a C/C++ static analyser.

http://cppcheck.sourceforge.net/

I find it very useful.

@RKSimon
Copy link
Collaborator

RKSimon commented Apr 13, 2019

Overzealous cppcheck warning

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla invalid Resolved as invalid, i.e. not a bug tools:bugpoint
Projects
None yet
Development

No branches or pull requests

4 participants