* gsubr.c (scm_gsubr_apply): From Radey Shouman
authorMikael Djurfeldt <djurfeldt@nada.kth.se>
Thu, 14 Aug 1997 14:58:25 +0000 (14:58 +0000)
committerMikael Djurfeldt <djurfeldt@nada.kth.se>
Thu, 14 Aug 1997 14:58:25 +0000 (14:58 +0000)
<shouman@zianet.com>: "The switch in scm_gsubr_apply that
dispatches on the number of actual args has a default case
reporting an internal error.  This is a vestige from a version
that mallocated a SCM vector to hold the arguments.  In the
current version this check is too late: if it ever happens we will
have already overstepped the bounds of the array.

Also, the patch [...] adds a check for too many actual arguments."

mdj: Removed check for "internal programming error".

libguile/gsubr.c

index f755f8f..c3e865d 100644 (file)
@@ -124,11 +124,15 @@ scm_gsubr_apply(args)
   SCM v[10];                   /* must agree with greatest supported arity */
   int typ = SCM_INUM(GSUBR_TYPE(self));
   int i, n = GSUBR_REQ(typ) + GSUBR_OPT(typ) + GSUBR_REST(typ);
+#if 0
+  SCM_ASSERT(n <= sizeof(v)/sizeof(SCM),
+            self, "internal programming error", s_gsubr_apply);
+#endif
   args = SCM_CDR(args);
   for (i = 0; i < GSUBR_REQ(typ); i++) {
 #ifndef RECKLESS
     if (SCM_IMP(args))
-      scm_wrong_num_args (SCM_SNAME(GSUBR_PROC(self)));
+      wnargs: scm_wrong_num_args (SCM_SNAME(GSUBR_PROC(self)));
 #endif
     v[i] = SCM_CAR(args);
     args = SCM_CDR(args);
@@ -143,8 +147,9 @@ scm_gsubr_apply(args)
   }
   if (GSUBR_REST(typ))
     v[i] = args;
+  else
+    SCM_ASRTGO(SCM_NULLP(args), wnargs);
   switch (n) {
-  default: scm_wta(self, "internal programming error", s_gsubr_apply);
   case 2: return (*fcn)(v[0], v[1]);
   case 3: return (*fcn)(v[0], v[1], v[2]);
   case 4: return (*fcn)(v[0], v[1], v[2], v[3]);