Skip to content

[BUG] does not bounds check iterators #51

@grizzlysmit

Description

@grizzlysmit

the following code segfaults:
using while first <= last { instead of while first < last {

To Reproduce
1.

main: () -> int
= {
    words: std::vector<std::string> = ( "decorated", "hello", "world" );

    first: std::vector<std::string>::iterator = words.begin();
    last : std::vector<std::string>::iterator = words.end();

    while first <= last {
        print_and_decorate(first*);
        first++;
    }
}

print_and_decorate: (thing:_) =
    std::cout << ">> " << thing << "\n";

 $ cppfront  pure2-bounds-safety-iterator.cpp2 -p -s
pure2-bounds-safety-iterator.cpp2... ok (all Cpp2, passes safety checks)

 $ g++ -std=c++20 pure2-bounds-safety-iterator.cpp -o pure2-bounds-safety-iterator
 $ ./pure2-bounds-safety-iterator 
>> decorated
>> hello
>> world
Segmentation fault (core dumped)
  1. I wanted cppfront to reject it

  2. it it passed and segfaulted on running

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions