Skip Menu |

This queue is for tickets about the YAML-Tiny CPAN distribution.

Report information
The Basics
Id: 89427
Status: resolved
Priority: 0/
Queue: YAML-Tiny

People
Owner: jkeenan [...] cpan.org
Requestors: jkeenan [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: LoadFile() has unreachable code
In the course of my work on boosting YAML-Tiny's code coverage I have come to believe that there is unreachable code in LoadFile() -- code which therefore can be and should be deleted. 633 sub LoadFile { 634 my $self = YAML::Tiny->read($_[0]); 635 unless ( $self ) { 636 Carp::croak("Failed to load YAML document from '" . ($_[0] || '') . "'"); 637 } The croak at line 636 only happens if $self is Perl-false. $self can only be false if YAML::Tiny->read() manages to run to completion without triggering any of several error conditions and still manage to return false. The final statement in read() is: 92 $class->read_string( $contents ); This can only be false if read_string() evaluates to Perl-false. Let's assume that read_string runs to completion, avoiding any of several conditions therewithin. In that case, we reach its final statement: 164 return $self; read_string() can only return false if the YAML::Tiny object has somehow become false or undefined within the method. There does not appear to be anything inside read_string() which would cause this to happen. If so, then read_string() can never return false. In that case, if read() reaches its final statement, it can never return false, either. And in that case, inside LoadFile() at line 635, $self can never be false and the block at line 636 can never be reached. The entire 'unless block from 635 to 637 is deletable. See: http://thenceforward.net/YAML-Tiny/coverage/blib-lib-YAML-Tiny-pm.html
On Sat Oct 12 19:07:00 2013, JKEENAN wrote: Show quoted text
> In the course of my work on boosting YAML-Tiny's code coverage I have > come to believe that there is unreachable code in LoadFile() -- code > which therefore can be and should be deleted. >
Patch attached.
Subject: 89427-Remove-unreachable-code.patch
From a6fde0efebf131900e08dd6879fdf8d37fafea7a Mon Sep 17 00:00:00 2001 From: jkeenan <jkeenan@cpan.org> Date: Sat, 12 Oct 2013 19:24:16 -0400 Subject: [PATCH] Remove unreachable code. For: https://rt.cpan.org/Ticket/Display.html?id=89427 --- lib/YAML/Tiny.pm | 3 --- 1 files changed, 0 insertions(+), 3 deletions(-) diff --git a/lib/YAML/Tiny.pm b/lib/YAML/Tiny.pm index 185b0d5..c9c2a3d 100644 --- a/lib/YAML/Tiny.pm +++ b/lib/YAML/Tiny.pm @@ -632,9 +632,6 @@ sub DumpFile { sub LoadFile { my $self = YAML::Tiny->read($_[0]); - unless ( $self ) { - Carp::croak("Failed to load YAML document from '" . ($_[0] || '') . "'"); - } if ( wantarray ) { return @$self; } else { -- 1.6.3.2
On Sat Oct 12 19:27:58 2013, JKEENAN wrote: Show quoted text
> On Sat Oct 12 19:07:00 2013, JKEENAN wrote:
> > In the course of my work on boosting YAML-Tiny's code coverage I have > > come to believe that there is unreachable code in LoadFile() -- code > > which therefore can be and should be deleted. > >
> > Patch attached.
Applied to master. commit 50eb7f6136ca79338751beaf8b341f9d2f1758a3 Author: jkeenan <jkeenan@cpan.org> AuthorDate: Sat Oct 12 19:24:16 2013 -0400 Commit: James E Keenan <jkeenan@cpan.org> CommitDate: Mon Oct 21 21:14:49 2013 -0400 Remove unreachable code. For: https://rt.cpan.org/Ticket/Display.html?id=89427