Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions scripts/gen-s-parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,10 @@ def instruction_parser():

printer.print_line("auto op = *keyword;")
printer.print_line("char buf[{}] = {{}};".format(inst_length + 1))
printer.print_line("// Ensure we do not copy more than the buffer can hold")
printer.print_line("if (op.size() >= sizeof(buf)) {")
printer.print_line(" goto parse_error;")
printer.print_line("}")
printer.print_line("memcpy(buf, op.data(), op.size());")

def print_leaf(expr, inst):
Expand Down Expand Up @@ -754,9 +758,11 @@ def emit(node, idx=0):
def print_header():
print("// DO NOT EDIT! This file generated by scripts/gen-s-parser.py\n")
print("// clang-format off\n")
print("// NOLINTBEGIN\n")


def print_footer():
print("\n// NOLINTEND")
print("\n// clang-format on")


Expand Down
8 changes: 8 additions & 0 deletions src/gen-s-parser.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

// clang-format off

// NOLINTBEGIN

auto op = *keyword;
char buf[33] = {};
// Ensure we do not copy more than the buffer can hold
if (op.size() >= sizeof(buf)) {
goto parse_error;
}
memcpy(buf, op.data(), op.size());
switch (buf[0]) {
case 'a': {
Expand Down Expand Up @@ -5151,4 +5157,6 @@ switch (buf[0]) {
parse_error:
return ctx.in.err(pos, "unrecognized instruction");

// NOLINTEND

// clang-format on