RimWorldCCLTeam / CommunityCoreLibrary

For full details see the official Ludeon Forums thread.
https://ludeon.com/forums/index.php?topic=16599.0
The Unlicense
60 stars 27 forks source link

PawnHasJobUsing() not inspects pawn.CurJob.targetC #187

Closed valuerr closed 7 years ago

valuerr commented 7 years ago

Just inspected a15-code with PVS-Studio and found follow:

// CommunityCoreLibrary\DLL_Project\Extensions\Thing_Extensions.cs

    public static bool PawnHasJobUsing( this Thing thing, Pawn pawn )
        {
            if(
                ( pawn == null ) ||
                ( pawn.CurJob == null )
            )
            {
                return false;
            }
            if(
                ( pawn.CurJob.targetA != null ) &&
                ( pawn.CurJob.targetA.Thing == thing )
            )
            {
                return true;
            }
            if(
                ( pawn.CurJob.targetB != null ) &&
                ( pawn.CurJob.targetB.Thing == thing )
            )
            {
                return true;
            }
            if(
                ( pawn.CurJob.targetB != null ) &&
                ( pawn.CurJob.targetB.Thing == thing )
            )
            {
                return true;
            }
            return false;
        }

There are two identical conditions with pawn.CurJob.targetB, it seems the last should be pawn.CurJob.targetC

valuerr commented 7 years ago

P.S. Jetbrains Resharper's inspection shows huge possible bugs, one of them for ex.:

// CommunityCoreLibrary\DLL_Project\Controller\SubControllers\SequencedInjectors\SequencedInjectionSets\SequencedInjectionSet_Designator.cs:41 Possible 'System.NullReferenceException'

    public override bool IsValid()
        {
            bool valid = true;

            if(
                ( designatorClass == null )||
                ( !designatorClass.IsSubclassOf( typeof( Designator ) ) )
            )
            {
                CCL_Log.Trace(
                    Verbosity.Validation,
                    string.Format( "Unable to resolve designatorClass '{0}'", designatorClass.FullName ),
                    Name
                );
                valid = false;
            }
           ...

logging can't log an incorrect call (with designatorClass==null ) due to the fact that logging itself causes System.NullReferenceException

ForsakenShell commented 7 years ago

Thanks for catching those, this is by far the easiest bug report to find solutions for. ;)