MEDIUM: pattern: ensure that sample types always cast into other types.

We want to ensure that a dynamically returned type will always have a
cast before calling the cast function. This is done in pattern_process()
and in stktable_fetch_key().
diff --git a/src/pattern.c b/src/pattern.c
index f6afb97..2820cf6 100644
--- a/src/pattern.c
+++ b/src/pattern.c
@@ -487,9 +487,21 @@
 		return NULL;
 
 	list_for_each_entry(conv_expr, &expr->conv_exprs, list) {
-		if (!pattern_casts[p->type][conv_expr->conv->in_type](p))
+		/* we want to ensure that p->type can be casted into
+		 * conv_expr->conv->in_type. We have 3 possibilities :
+		 *  - NULL   => not castable.
+		 *  - c_none => nothing to do (let's optimize it)
+		 *  - other  => apply cast and prepare to fail
+		 */
+		if (!pattern_casts[p->type][conv_expr->conv->in_type])
+			return NULL;
+
+		if (pattern_casts[p->type][conv_expr->conv->in_type] != c_none &&
+		    !pattern_casts[p->type][conv_expr->conv->in_type](p))
 			return NULL;
 
+		/* OK cast succeeded */
+
 		/* force the output type after a cast */
 		p->type = conv_expr->conv->in_type;
 		if (!conv_expr->conv->process(conv_expr->arg_p, p))