From: Tony Cook Date: Wed, 2 Jan 2019 07:50:48 +0000 (+1100) Subject: avoid dead code in i_tt_glyph_names() X-Git-Tag: v1.009~25 X-Git-Url: http://git.imager.perl.org/imager.git/commitdiff_plain/ea3099db176771d11c73784c81dd212985fdd24b avoid dead code in i_tt_glyph_names() CID 185321 --- diff --git a/Changes b/Changes index 02bb4040..97c275a6 100644 --- 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. + - avoid dead code in i_tt_glyph_names(). CID 185321. + Imager 1.008 - 31 Dec 2018 ============ diff --git a/Imager.xs b/Imager.xs index e184078a..7f428e33 100644 --- 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]; - SSize_t count = 0; 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; } - EXTEND(SP, count+1); + EXTEND(SP, 1); 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 { - ST(count) = &PL_sv_undef; + PUSHs(&PL_sv_undef); } - ++count; } - XSRETURN(count); #endif diff --git a/t/350-font/020-tt.t b/t/350-font/020-tt.t index 5609a853..4064c4ab 100644 --- a/t/350-font/020-tt.t +++ b/t/350-font/020-tt.t @@ -1,6 +1,6 @@ #!perl -w use strict; -use Test::More tests => 97; +use Test::More; $|=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"); + + # 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}); @@ -331,3 +335,5 @@ SKIP: ok(1, "end of code"); } + +done_testing();