[OCaml] Fix segfaults when too few arguments are passed to a function
Prevent segfaults when too few arguments are passed to a function. Length checks are not needed for the wrappers of overloaded functions -- the generated dispatch function already checks. Add default_args_runme.ml. Fix minor errors in some runtime tests. Extra args were being passed in some cases.
This commit is contained in:
parent
7b0402f89b
commit
071803f000
8 changed files with 77 additions and 9 deletions
|
|
@ -553,7 +553,18 @@ public:
|
|||
|
||||
numargs = emit_num_arguments(l);
|
||||
numreq = emit_num_required(l);
|
||||
|
||||
if (!isOverloaded) {
|
||||
if (numargs > 0) {
|
||||
if (numreq > 0) {
|
||||
Printf(f->code, "if (caml_list_length(args) < %d || caml_list_length(args) > %d) {\n", numreq, numargs);
|
||||
} else {
|
||||
Printf(f->code, "if (caml_list_length(args) > %d) {\n", numargs);
|
||||
}
|
||||
Printf(f->code, "caml_invalid_argument(\"Incorrect number of arguments passed to '%s'\");\n}\n", iname);
|
||||
} else {
|
||||
Printf(f->code, "if (caml_list_length(args) > 0) caml_invalid_argument(\"'%s' takes no arguments\");\n", iname);
|
||||
}
|
||||
}
|
||||
Printf(f->code, "swig_result = Val_unit;\n");
|
||||
|
||||
// Now write code to extract the parameters (this is super ugly)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue