From 1c46fc4dd4ebb042e6600f1c3a25ecbac1c41f13 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?=
 <grubba@grubba.org>
Date: Thu, 3 Jul 2014 16:58:52 +0200
Subject: [PATCH] Stdio.Stat: Survive casts to subtyped arrays (and mappings).

When casting an object to eg array(int), lfun::cast() gets the string
"array(int)". This used to cause Stdio.Stat::cast() to fail.
---
 src/modules/_Stdio/stat.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/modules/_Stdio/stat.c b/src/modules/_Stdio/stat.c
index 6ce6aa49ba..f0158ddea8 100644
--- a/src/modules/_Stdio/stat.c
+++ b/src/modules/_Stdio/stat.c
@@ -775,7 +775,10 @@ static void stat_cast(INT32 args)
       SIMPLE_TOO_FEW_ARGS_ERROR("Stat cast",1);
    if (TYPEOF(sp[-args]) == T_STRING && !sp[-args].u.string->size_shift)
    {
-      if (strcmp(sp[-args].u.string->str,"array")==0)
+      /* NB: We only look at the prefix, and let the main cast function
+       *     handle any subtypes.
+       */
+      if (!strncmp(sp[-args].u.string->str, "array", 5))
       {
 	 pop_n_elems(args);
 	 push_int(0);
@@ -783,7 +786,7 @@ static void stat_cast(INT32 args)
 	 stat_index(2);
 	 return;
       }
-      if (strcmp(sp[-args].u.string->str,"mapping")==0)
+      if (!strncmp(sp[-args].u.string->str, "mapping", 7))
       {
         stat_indices(0);
         stat_values(0);
@@ -793,7 +796,7 @@ static void stat_cast(INT32 args)
       }
    }
    SIMPLE_BAD_ARG_ERROR("Stat cast",1,
-			"string(\"array\")");
+			"string(\"array\"|\"mapping\")");
 }
 
 static void stat__sprintf(INT32 args)
-- 
GitLab