cppfront icon indicating copy to clipboard operation
cppfront copied to clipboard

[BUG] does not bounds check iterators

Open grizzlysmit opened this issue 2 years ago • 0 comments

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

grizzlysmit avatar Oct 08 '22 03:10 grizzlysmit