Skip to content

Commit

Permalink
Throw badfun if trying to call improper fun; was causing NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
krestenkrab committed Nov 8, 2010
1 parent 15fc136 commit 6e04844
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/main/java/erjang/ERT.java
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,10 @@ public static String describe_exception(Throwable e) {
return sw.toString();
}

public static void test_fun(EObject orig, EFun fun) {
if (fun == null)
throw new ErlangError(am_badfun, orig);
}

static EInteger max_send_time = ERT.box(4294967295L);
static ESmall zero = ERT.box(0);
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/erjang/beam/CompilerVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -1775,11 +1775,16 @@ public void visitInsn(BeamOpcode opcode, Arg[] in, Arg out) {

int nargs = in.length - 1;
push(in[nargs], EOBJECT_TYPE);

mv.visitInsn(DUP);

String funtype = EFUN_NAME + nargs;

mv.visitMethodInsn(INVOKESTATIC, funtype, "cast", "("
+ EOBJECT_DESC + ")L" + funtype + ";");

mv.visitInsn(DUP_X1);

mv.visitMethodInsn(INVOKESTATIC, ERT_NAME, "test_fun", "(" + EOBJECT_DESC + EFUN_DESCRIPTOR + ")V");

mv.visitVarInsn(ALOAD, 0); // load proc
for (int i = 0; i < nargs; i++) {
Expand Down

0 comments on commit 6e04844

Please sign in to comment.