X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=misc%2Ftools%2Fprogs-analyzer.pl;h=e8d7a21260382821c053077e18343beee5f151c2;hb=9d330c09ab63900342f1977c37a83753e730b794;hp=7037c8a03a76387d0b28a1dd19de93d70376caee;hpb=a7012bfde8762a50913d41c4b656adc07004cb65;p=xonotic%2Fxonotic.git diff --git a/misc/tools/progs-analyzer.pl b/misc/tools/progs-analyzer.pl old mode 100644 new mode 100755 index 7037c8a0..e8d7a212 --- a/misc/tools/progs-analyzer.pl +++ b/misc/tools/progs-analyzer.pl @@ -1,3 +1,5 @@ +#!/usr/bin/perl + use strict; use warnings; use Digest::SHA; @@ -125,6 +127,10 @@ sub checkop($) { return { a => 'inglobal', b => 'inglobalfunc' }; } + if($op =~ /^INVALID#/) + { + return { isinvalid => 1 }; + } return { a => 'inglobal', b => 'inglobal', c => 'outglobal' }; } @@ -673,6 +679,10 @@ sub find_uninitialized_locals($$) } } + if($c->{isinvalid}) + { + ++$warned{$ip}{''}{"Invalid opcode"}; + } for(qw(a b c)) { my $type = $c->{$_}; @@ -898,7 +908,7 @@ sub detect_constants($) use constant GLOBALFLAG_U => 64; # unused use constant GLOBALFLAG_P => 128; # possibly parameter passing use constant GLOBALFLAG_D => 256; # has a def - my @globalflags = (GLOBALFLAG_Q | GLOBALFLAG_U) x @{$progs->{globals}}; + my @globalflags = (GLOBALFLAG_Q | GLOBALFLAG_U) x (@{$progs->{globals}} + 2); for(@{$progs->{functions}}) { @@ -1000,7 +1010,7 @@ sub detect_constants($) # add missing def if(!($globalflags[$_->{ofs}+$i] & GLOBALFLAG_D)) { - print "Missing globaldef for $_->{debugname}[$i] at $_->{ofs}\n"; + print "Missing globaldef for a component@{[defined $_->{debugname} ? ' of ' . $_->{debugname} : '']} at $_->{ofs}+$i\n"; push @extradefs, { type => { saved => 0, @@ -1181,7 +1191,7 @@ sub parse_progs($) die "Out of range name in globaldef $_" if $g->{s_name} < 0 || $g->{s_name} >= length $p{strings}; my $name = $p{getstring}->($g->{s_name}); - die "Out of range ofs in globaldef $_ (name: \"$name\")" + die "Out of range ofs $g->{ofs} in globaldef $_ (name: \"$name\")" if $g->{ofs} >= $p{globals}; } @@ -1195,7 +1205,7 @@ sub parse_progs($) die "Out of range name in fielddef $_" if $g->{s_name} < 0 || $g->{s_name} >= length $p{strings}; my $name = $p{getstring}->($g->{s_name}); - die "Out of range ofs in globaldef $_ (name: \"$name\")" + die "Out of range ofs $g->{ofs} in fielddef $_ (name: \"$name\")" if $g->{ofs} >= $p{header}{entityfields}; } @@ -1258,8 +1268,18 @@ sub parse_progs($) elsif($type eq 'inglobalvec') { $s->{$_} &= 0xFFFF; - die "Out of range global offset in statement $ip - cannot continue" - if $s->{$_} >= @{$p{globals}}-2; + if($c->{isreturn}) + { + die "Out of range global offset in statement $ip - cannot continue" + if $s->{$_} >= @{$p{globals}}; + print "Potentially out of range global offset in statement $ip - may crash engines" + if $s->{$_} >= @{$p{globals}}-2; + } + else + { + die "Out of range global offset in statement $ip - cannot continue" + if $s->{$_} >= @{$p{globals}}-2; + } } elsif($type eq 'outglobal') {