Menu

#4 $length undefined in sub valueString

open
nobody
None
5
2003-10-09
2003-10-09
Anonymous
No

In DICOM_element.pm, in sub valueString, if the $code is
not in the recognized DICOM fields, it is possible that $length
is undefined (line 228), and a run-time error is printed out. I
corrected this (sort of) by checking to see if $length was
defined, as follows.

sub valueString {
my $this = shift;
my %hash = %$this;
my ($code, $value) = @hash{qw(code value)};

if ($code =~ /OX|SQ/) {
$value = "";
} elsif ($code eq '--') {
# Don't return value if it contains binary characters.
if (defined($length)) {
foreach my $i (0..($length - 1)) {
my $val = ord(substr($value, $i, 1));
$value = "" if ($val > 0x0 and ($val < 0x20 or $val
>= 0x80));
}
} else {
$value = "";
}
}

return $value;
}

I'm not sure if this is peculiar to the flavor of DICOM that is
in these files, but the perl error messages "Use of
uninitialized value in subtraction (-)" were a bit distracting.
--
John Antolak <jantolak@mdanderson.org>

Discussion


Log in to post a comment.