Browse Source

Suppress most of the false positive on out-of-bound access.
The affect of this change can only be checked after the next Coverity Scan run on this Thursday.

Yao Wei Tjong 姚伟忠 10 years ago
parent
commit
0e031852d1

+ 1 - 1
.travis.yml

@@ -138,7 +138,7 @@ addons:
       name: urho3d/Urho3D
       description: Urho3D is a free lightweight, cross-platform 2D and 3D game engine implemented in C++ and released under the MIT license. Greatly inspired by OGRE and Horde3D.
     notification_email: [email protected]
-    build_command_prepend: rake cmake URHO3D_LUAJIT=1 URHO3D_LUAJIT_AMALG=1 URHO3D_SAMPLES=1 URHO3D_TOOLS=1 URHO3D_EXTRAS=1 URHO3D_LIB_TYPE=SHARED
+    build_command_prepend: rake cmake URHO3D_LUAJIT=1 URHO3D_LUAJIT_AMALG=1 URHO3D_SAMPLES=1 URHO3D_TOOLS=1 URHO3D_EXTRAS=1 URHO3D_DATABASE_SQLITE=1 URHO3D_LIB_TYPE=SHARED
     build_command: rake make numjobs=4
     branch_pattern: .*Coverity-Scan$
 env:

+ 5 - 0
CMake/Modules/Urho3D-CMake-common.cmake

@@ -247,6 +247,11 @@ if (URHO3D_TESTING)
     add_definitions (-DURHO3D_TESTING)
 endif ()
 
+# Enable coverity scan modeling
+if ($ENV{COVERITY_SCAN_BRANCH})
+    add_definitions (-DCOVERITY_SCAN_MODEL)
+endif ()
+
 # Enable SSE instruction set. Requires Pentium III or Athlon XP processor at minimum.
 if (URHO3D_SSE)
     add_definitions (-DURHO3D_SSE)

+ 41 - 0
Source/Extras/CoverityScan/model.cpp

@@ -0,0 +1,41 @@
+//
+// Copyright (c) 2008-2015 the Urho3D project.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+/* Coverity Scan model
+ *
+ * This is a modeling file for Coverity Scan. Modeling helps to avoid false
+ * positives.
+ *
+ * - A model file can't import any header files.
+ * - Therefore only some built-in primitives like int, char and void are
+ *   available but not wchar_t, NULL etc.
+ * - Modeling doesn't need full structs and typedefs. Rudimentary structs
+ *   and similar types are sufficient.
+ * - An uninitialized local pointer is not an error. It signifies that the
+ *   variable could be either NULL or have some data.
+ *
+ * Coverity Scan doesn't pick up modifications automatically. The model file
+ * must be uploaded by an admin in the analysis settings of
+ * https://scan.coverity.com/projects/urho3d-urho3d?tab=analysis_settings
+ */
+
+#define URHO3D_API __attribute__((visibility("default")))

+ 10 - 0
Source/Urho3D/Container/Vector.h

@@ -175,7 +175,17 @@ public:
     }
 
     /// Add an element at the end.
+#ifndef COVERITY_SCAN_MODEL
     void Push(const T& value) { Resize(size_ + 1, &value); }
+#else
+    // FIXME: Attempt had been made to use this model in the Coverity-Scan model file without any success
+    // Probably because the model had generated a different mangled name than the one used by static analyzer
+    void Push(const T& value)
+    {
+        T array[] = {value};
+        Resize(size_ + 1, array);
+    }
+#endif
 
     /// Add another vector at the end.
     void Push(const Vector<T>& vector) { Resize(size_ + vector.size_, vector.Buffer()); }