peter-winter / ctpg

Compile Time Parser Generator is a C++ single header library which takes a language description as a C++ code and turns it into a LR1 table parser with a deterministic finite automaton lexical analyzer, all in compile time.
MIT License
460 stars 24 forks source link

Invoking undefined behaviour when using an rvalue in the constructor of stdex::cvector #7

Closed hrco159753 closed 3 years ago

hrco159753 commented 3 years ago

This is my first pull request :fireworks:, so yeah..., but here you're invoking an undefined behaviour(for count larger then 1) by moving an rvalue into the emplace_back function count times. It'd be fine if you were to move only once, but because you're moving it more than once you can't really expect any other element after the first to be in the valid state inside the _thedata member field.

https://github.com/peter-winter/ctpg/blob/99af8d2f712a3bfdfbe37d858fac391da2c78240/ctpg.hpp#L114-L119

peter-winter commented 3 years ago

Thanks. It is not used anywhere, this constructor literally doesn't make sense.

peter-winter commented 3 years ago

Fixed