diff libinterp/octave-value/ov-ch-mat.cc @ 15501:814c4b0d5c49

make numeric mapper functions throw error for char args (bug #37535) * ov-base.h (octave_base_value::get_umap_name): Now protected instead of private. * ov-ch-mat.cc (octave_char_matrix::map): Special cases for umap_abs, umap_ceil, umap_fix, umap_floor, umap_imag, umap_isinf, umap_isnan, umap_real, and umap_round. Error for all other mappers that expect numeric arguments.
author John W. Eaton <jwe@octave.org>
date Thu, 11 Oct 2012 12:56:56 -0400
parents c9844b82945f
children ffd1a99733bd
line wrap: on
line diff
--- a/libinterp/octave-value/ov-ch-mat.cc	Thu Oct 11 08:54:08 2012 +0200
+++ b/libinterp/octave-value/ov-ch-mat.cc	Thu Oct 11 12:56:56 2012 -0400
@@ -172,6 +172,8 @@
 octave_value
 octave_char_matrix::map (unary_mapper_t umap) const
 {
+  octave_value retval;
+
   switch (umap)
     {
 #define STRING_MAPPER(UMAP,FCN,TYPE) \
@@ -194,10 +196,26 @@
     STRING_MAPPER (xtolower, std::tolower, char);
     STRING_MAPPER (xtoupper, std::toupper, char);
 
-    default:
+    // For Matlab compatibility, these should work on ASCII values
+    // without error or warning.
+    case umap_abs:
+    case umap_ceil:
+    case umap_fix:
+    case umap_floor:
+    case umap_imag:
+    case umap_isinf:
+    case umap_isnan:
+    case umap_real:
+    case umap_round:
       {
         octave_matrix m (array_value (true));
         return m.map (umap);
       }
+
+    default:
+      error ("%s: expecting numeric argument", get_umap_name (umap));
+      break;
     }
+
+  return retval;
 }