]> git.imager.perl.org - imager.git/commitdiff
avoid dead code in i_tt_glyph_names()
authorTony Cook <tony@develop-help.com>
Wed, 2 Jan 2019 07:50:48 +0000 (18:50 +1100)
committerTony Cook <tony@develop-help.com>
Wed, 2 Jan 2019 07:50:48 +0000 (18:50 +1100)
CID 185321

Changes
Imager.xs
t/350-font/020-tt.t

diff --git a/Changes b/Changes
index 02bb4040a36a80fca6e87984f0c66a6feab50d9a..97c275a67b3ed8ff092424bd5c02019f204434b3 100644 (file)
--- a/Changes
+++ b/Changes
@@ -64,6 +64,8 @@ High severity:
  - gradgen() allocated the wrong amount of space (always too much) for
    the color array.  CID 185291.
 
  - gradgen() allocated the wrong amount of space (always too much) for
    the color array.  CID 185291.
 
+ - avoid dead code in i_tt_glyph_names(). CID 185321.
+
 Imager 1.008 - 31 Dec 2018
 ============
 
 Imager 1.008 - 31 Dec 2018
 ============
 
index e184078a5861c8668180d306b5fcc2505a4f7222..7f428e338e462b47e06503b70e871d5213cff218 100644 (file)
--- a/Imager.xs
+++ b/Imager.xs
@@ -2512,7 +2512,6 @@ i_tt_glyph_name(handle, text_sv, utf8 = 0)
         size_t len;
         size_t outsize;
         char name[255];
         size_t len;
         size_t outsize;
         char name[255];
-       SSize_t count = 0;
       PPCODE:
         i_clear_error();
         text = SvPV(text_sv, work_len);
       PPCODE:
         i_clear_error();
         text = SvPV(text_sv, work_len);
@@ -2534,16 +2533,14 @@ i_tt_glyph_name(handle, text_sv, utf8 = 0)
             ch = *text++;
             --len;
           }
             ch = *text++;
             --len;
           }
-          EXTEND(SP, count+1);
+          EXTEND(SP, 1);
           if ((outsize = i_tt_glyph_name(handle, ch, name, sizeof(name))) != 0) {
           if ((outsize = i_tt_glyph_name(handle, ch, name, sizeof(name))) != 0) {
-           ST(count) = sv_2mortal(newSVpv(name, 0));
+           PUSHs(sv_2mortal(newSVpv(name, 0)));
           }
           else {
           }
           else {
-           ST(count) = &PL_sv_undef;
+           PUSHs(&PL_sv_undef);
           }
           }
-          ++count;
         }
         }
-       XSRETURN(count);
 
 #endif 
 
 
 #endif 
 
index 5609a853955333212d87a8b0fdbf8e83a66925ee..4064c4abc79b0230097c20d4f480aefe111a0c62 100644 (file)
@@ -1,6 +1,6 @@
 #!perl -w
 use strict;
 #!perl -w
 use strict;
-use Test::More tests => 97;
+use Test::More;
 
 $|=1;
 
 
 $|=1;
 
@@ -151,6 +151,10 @@ SKIP:
     is($glyph_names[0], 'exclam', "check exclam name OO");
     ok(!defined($glyph_names[1]), "check for no J name OO");
     is($glyph_names[2], 'slash', "check slash name OO");
     is($glyph_names[0], 'exclam', "check exclam name OO");
     ok(!defined($glyph_names[1]), "check for no J name OO");
     is($glyph_names[2], 'slash', "check slash name OO");
+
+    # check invalid utf8
+    my @bad = $hcfont->glyph_names(string => "!/\xC0", utf8 => 1);
+    is(@bad, 0, "should return nothing for invalid UTF-8");
     
     print "# ** name table of the test font **\n";
     Imager::i_tt_dump_names($hcfont->{id});
     
     print "# ** name table of the test font **\n";
     Imager::i_tt_dump_names($hcfont->{id});
@@ -331,3 +335,5 @@ SKIP:
 
   ok(1, "end of code");
 }
 
   ok(1, "end of code");
 }
+
+done_testing();