diff --git a/mach/proto/ncg/codegen.c b/mach/proto/ncg/codegen.c
index 0e54d1e6c..e7c64ef15 100644
--- a/mach/proto/ncg/codegen.c
+++ b/mach/proto/ncg/codegen.c
@@ -152,7 +152,7 @@ unsigned codegen(codep,ply,toplevel,costlimit,forced) byte *codep; unsigned cost
 			int j, nargs;
 			getint(i,bp);
 			getint(nargs,bp);
-			assert(nargs < MAXPROCARG);
+			assert(nargs <= MAXPROCARG);
 			for (j = 0; j < nargs; j++) {
 				getint(procarg[j],bp);
 			}
diff --git a/mach/proto/ncg/subr.c b/mach/proto/ncg/subr.c
index e5f6cca0a..c25cb0ba5 100644
--- a/mach/proto/ncg/subr.c
+++ b/mach/proto/ncg/subr.c
@@ -324,6 +324,14 @@ distance(cindex) {
 				return(100);
 			if (expsize<toksize)
 				return(99-i);
+
+			/* Now we have a match in size, but it is not exact.
+			   Therefore, make sure that we can at least
+			   create it from the stack!
+			*/
+			if (! from_stack(&machsets[tokexp])) {
+				return MAXINT;
+			}
 		} else
 			exact++;
 	}