The static code analyzer reports some errors

SkyWalker

New member
https://github.com/Tencent/TscanCode
We use TscanCode to make our project robust.
If there are errors, we have to fix them.
For example:
BehaviorSource.cs line="76" msg="comparing [mTaskData] to null at line 73 implies that [mTaskData] might be null.Dereferencing null pointer [mTaskData]"
C#:
        public bool CheckForSerialization(bool force, BehaviorSource behaviorSource = null)
        {
            // mark the non-external behavior tree version as serialized since that property will change.
            bool hasSerialized = (behaviorSource != null ? behaviorSource.HasSerialized : HasSerialized);
            if (!hasSerialized || force) {
                if (behaviorSource != null) {
                    behaviorSource.HasSerialized = true;
                } else {
                    HasSerialized = true;
                }
                if (mTaskData != null && !string.IsNullOrEmpty(mTaskData.JSONSerialization)) {
                    JSONDeserialization.Load(mTaskData, behaviorSource == null ? this : behaviorSource);
                } else { // binary serialization
                    BinaryDeserialization.Load(mTaskData, behaviorSource == null ? this : behaviorSource);
                }
                return true;
            }
            return false;
        }
I fixed it by moving “mTaskData != null &&” ahead. TscanCode didn't report the error.
C#:
        public bool CheckForSerialization(bool force, BehaviorSource behaviorSource = null)
        {
            // mark the non-external behavior tree version as serialized since that property will change.
            bool hasSerialized = (behaviorSource != null ? behaviorSource.HasSerialized : HasSerialized);
            if (mTaskData != null && (!hasSerialized || force)) {
                if (behaviorSource != null) {
                    behaviorSource.HasSerialized = true;
                } else {
                    HasSerialized = true;
                }
                if (!string.IsNullOrEmpty(mTaskData.JSONSerialization)) {
                    JSONDeserialization.Load(mTaskData, behaviorSource == null ? this : behaviorSource);
                } else { // binary serialization
                    BinaryDeserialization.Load(mTaskData, behaviorSource == null ? this : behaviorSource);
                }
                return true;
            }
            return false;
        }
Am I right?
There are other errors in Behavior Designer. Could you please scan and fix them?
 
Last edited:
That is correct. I just ran the static code analyzer and fixed a couple, but most of the errors reported related to serialized fields which can safely be ignored.
 
Top