[svn:parrot] r37555 - in trunk: src/string t/op

cotto at svn.parrot.org cotto at svn.parrot.org
Wed Mar 18 20:22:39 UTC 2009


Author: cotto
Date: Wed Mar 18 20:22:38 2009
New Revision: 37555
URL: https://trac.parrot.org/parrot/changeset/37555

Log:
[string] handle negative encoding numbers in a non-explodey manner
fuzzing++

Modified:
   trunk/src/string/encoding.c
   trunk/t/op/string_cs.t

Modified: trunk/src/string/encoding.c
==============================================================================
--- trunk/src/string/encoding.c	Wed Mar 18 20:03:35 2009	(r37554)
+++ trunk/src/string/encoding.c	Wed Mar 18 20:22:38 2009	(r37555)
@@ -251,7 +251,8 @@
 Parrot_get_encoding(SHIM_INTERP, INTVAL number_of_encoding)
 {
     ASSERT_ARGS(Parrot_get_encoding)
-    if (number_of_encoding >= all_encodings->n_encodings)
+    if (number_of_encoding >= all_encodings->n_encodings || 
+        number_of_encoding < 0)
         return NULL;
     return all_encodings->enc[number_of_encoding].encoding;
 }

Modified: trunk/t/op/string_cs.t
==============================================================================
--- trunk/t/op/string_cs.t	Wed Mar 18 20:03:35 2009	(r37554)
+++ trunk/t/op/string_cs.t	Wed Mar 18 20:22:38 2009	(r37555)
@@ -6,7 +6,7 @@
 use warnings;
 use lib qw( . lib ../lib ../../lib );
 use Test::More;
-use Parrot::Test tests => 51;
+use Parrot::Test tests => 52;
 use Parrot::Config;
 
 =head1 NAME
@@ -519,6 +519,14 @@
 CODE
 t\xf6tsch
 OUTPUT
+
+    pasm_error_output_like( <<'CODE', <<"OUTPUT", "negative encoding number" );
+    trans_encoding S2, 'foo', -1
+    end
+CODE
+/encoding #-1 not found/
+OUTPUT
+
     pasm_output_is( <<'CODE', <<"OUTPUT", "unicode downcase - transcharset" );
     set S0, iso-8859-1:"TÖTSCH"
     find_charset I0, "unicode"


More information about the parrot-commits mailing list