Skip to content

Commit

Permalink
Handle holes in zend_get_opcode_id()
Browse files Browse the repository at this point in the history
Some opcodes may currently not be allocated.
  • Loading branch information
nikic committed Dec 30, 2021
1 parent 8869bbe commit b63e4cf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Zend/zend_vm_gen.php
Original file line number Diff line number Diff line change
Expand Up @@ -2688,7 +2688,8 @@ function gen_vm($def, $skel) {
fputs($f, "ZEND_API zend_uchar zend_get_opcode_id(const char *name, size_t length) {\n");
fputs($f, "\tzend_uchar opcode;\n");
fputs($f, "\tfor (opcode = 0; opcode < (sizeof(zend_vm_opcodes_names) / sizeof(zend_vm_opcodes_names[0])) - 1; opcode++) {\n");
fputs($f, "\t\tif (strncmp(zend_vm_opcodes_names[opcode], name, length) == 0) {\n");
fputs($f, "\t\tconst char *opcode_name = zend_vm_opcodes_names[opcode];\n");
fputs($f, "\t\tif (opcode_name && strncmp(opcode_name, name, length) == 0) {\n");
fputs($f, "\t\t\treturn opcode;\n");
fputs($f, "\t\t}\n");
fputs($f, "\t}\n");
Expand Down
3 changes: 2 additions & 1 deletion Zend/zend_vm_opcodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,8 @@ ZEND_API uint32_t ZEND_FASTCALL zend_get_opcode_flags(zend_uchar opcode) {
ZEND_API zend_uchar zend_get_opcode_id(const char *name, size_t length) {
zend_uchar opcode;
for (opcode = 0; opcode < (sizeof(zend_vm_opcodes_names) / sizeof(zend_vm_opcodes_names[0])) - 1; opcode++) {
if (strncmp(zend_vm_opcodes_names[opcode], name, length) == 0) {
const char *opcode_name = zend_vm_opcodes_names[opcode];
if (opcode_name && strncmp(opcode_name, name, length) == 0) {
return opcode;
}
}
Expand Down

0 comments on commit b63e4cf

Please sign in to comment.