Skip Menu |

This queue is for tickets about the Parse-DMIDecode CPAN distribution.

Report information
The Basics
Id: 54956
Status: open
Priority: 0/
Queue: Parse-DMIDecode

People
Owner: Nobody in particular
Requestors: dmo [...] roaringpenguin.com
Cc:
AdminCc:

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



Subject: [PATCH] Initialize $data{structures} to 0 when it's not found.
Date: Wed, 24 Feb 2010 17:16:17 -0500
To: bug-parse-dmidecode [...] rt.cpan.org
From: "Dave O'Neill" <dmo [...] roaringpenguin.com>
This prevents a "Use of uninitialized value" warning when parsing incomplete dmidecode output diff --git a/lib/Parse/DMIDecode.pm b/lib/Parse/DMIDecode.pm index 441bff1..d5835c0 100644 --- a/lib/Parse/DMIDecode.pm +++ b/lib/Parse/DMIDecode.pm @@ -170,10 +170,13 @@ sub parse { } } - for (qw(dmidecode structures bytes dmi smbios location)) { + for (qw(dmidecode bytes dmi smbios location)) { $data{$_} = undef if !exists $data{$_}; } + # {structures} should be zero if missing, as we use it in comparisons below. + $data{structures} = 0 if !exists $data{structures}; + my $raw_handle_data = ''; for (; $i < @lines; $i++) { if ($lines[$i] =~ /^Handle [0-9A-Fx]+/) { -- Dave O'Neill <dmo@roaringpenguin.com> Roaring Penguin Software Inc. +1 (613) 231-6599 http://www.roaringpenguin.com/ For CanIt technical support, please mail: support@roaringpenguin.com
Dne St 24.úno.2010 17:17:18, dmo@roaringpenguin.com napsal(a): Show quoted text
> This prevents a "Use of uninitialized value" warning when parsing > incomplete > dmidecode output > > diff --git a/lib/Parse/DMIDecode.pm b/lib/Parse/DMIDecode.pm > index 441bff1..d5835c0 100644 > --- a/lib/Parse/DMIDecode.pm > +++ b/lib/Parse/DMIDecode.pm > @@ -170,10 +170,13 @@ sub parse { > } > } > > - for (qw(dmidecode structures bytes dmi smbios location)) { > + for (qw(dmidecode bytes dmi smbios location)) { > $data{$_} = undef if !exists $data{$_}; > } > > + # {structures} should be zero if missing, as we use it in > comparisons below. > + $data{structures} = 0 if !exists $data{structures}; > + > my $raw_handle_data = ''; > for (; $i < @lines; $i++) { > if ($lines[$i] =~ /^Handle [0-9A-Fx]+/) {
The $data{structures} value is used only at two places. One is a sanity check that we parsed all DMI handles ("Only parsed %d structures when %d were expected" warning), and the other is the parse() (and probe()) return value. In my opinion, the sanity check should be skipped if DMI does not report a number of the structures. It does not make sense to check against a made-up number. The return values are nowhere used or documented. I this light I would simply skip the sanity check and left the value undefined. There is actually a third place where $data{structures} is used and that's in t/40regression_test.t test. But this distribution does not deliver any test data for that tests and hence the test is void. The tests actually repeates the sanity test from Parse::DMIDecode::parse() I described as the first place. Either dmidecode output without reported structures value is legal and then the test should be changed, or the $data{structures} should be faked to a number of parses handles, if it is not present in the dmidecode output.
Dne Čt 26.bře.2020 06:25:43, ppisar napsal(a): Show quoted text
> Either dmidecode output without reported structures value is legal
dmidecode-3.2 sources reveal that the number of structures is printed only if DMI reports it different from 0 or if it is not a SMBIOS version 3 machine ("_SM3_" identifier). A specification of the version 3 appeared in the year of 2015, but e.g. my laptop from 2016 still has 2.8 version. I believe we will see more and more machines like that.