https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110974
Bug ID: 110974
Summary: format out of bounds read on invalid format string
"{:{}."
Product: gcc
Version: 13.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: gcc at pauldreik dot se
Target Milestone: ---
The following code:
#include <cstdio>
#include <format>
#include <string_view>
int main() {
double v = 0;
// use a char buffer instead of a literal
// to avoid the implicit null terminator
char fmtbuf[] = {'{', ':', '{', '}', '.'};
std::string_view fmt{&fmtbuf[0], sizeof(fmtbuf)};
std::puts(std::vformat(fmt, std::make_format_args(v)).c_str());
}
causes an out of bounds read when compiled with gcc 13.2, as well as the
current trunk.
Link to reproducer: https://godbolt.org/z/6qPMdse5o