TestNetscapePlugIn: Fix remaining static analyzer warnings
authorddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 5 Dec 2015 04:31:49 +0000 (04:31 +0000)
committerddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 5 Dec 2015 04:31:49 +0000 (04:31 +0000)
<http://webkit.org/b/151888>

Reviewed by Alexey Proskuryakov.

Fixes the following static analyzer warnings:
    Tools/DumpRenderTree/TestNetscapePlugIn/main.cpp:101:9: warning: Called function pointer is null (null dereference)
            CRASH();
            ^~~~~~~
    Tools/DumpRenderTree/TestNetscapePlugIn/main.cpp:46:5: note: expanded from macro 'CRASH'
        ((void(*)())0)(); /* More reliable, but doesn't say BBADBEEF */ \
        ^~~~~~~~~~~~~~~~
    Tools/DumpRenderTree/TestNetscapePlugIn/main.cpp:375:12: warning: Access to field 'pluginTest' results in a dereference of a null pointer (loaded from variable 'obj')
        return obj->pluginTest->NPP_SetWindow(window);
               ^~~~~~~~~~~~~~~
    2 warnings generated.

* DumpRenderTree/TestNetscapePlugIn/main.cpp:
(CRASH): Use __builtin_trap() for gcc/clang.
(NPP_SetWindow): Add early return if obj is nullptr.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@193509 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/DumpRenderTree/TestNetscapePlugIn/main.cpp

index 9dac3b5..3d7c3ff 100644 (file)
@@ -1,3 +1,26 @@
+2015-12-04  David Kilzer  <ddkilzer@apple.com>
+
+        TestNetscapePlugIn: Fix remaining static analyzer warnings
+        <http://webkit.org/b/151888>
+
+        Reviewed by Alexey Proskuryakov.
+
+        Fixes the following static analyzer warnings:
+            Tools/DumpRenderTree/TestNetscapePlugIn/main.cpp:101:9: warning: Called function pointer is null (null dereference)
+                    CRASH();
+                    ^~~~~~~
+            Tools/DumpRenderTree/TestNetscapePlugIn/main.cpp:46:5: note: expanded from macro 'CRASH'
+                ((void(*)())0)(); /* More reliable, but doesn't say BBADBEEF */ \
+                ^~~~~~~~~~~~~~~~
+            Tools/DumpRenderTree/TestNetscapePlugIn/main.cpp:375:12: warning: Access to field 'pluginTest' results in a dereference of a null pointer (loaded from variable 'obj')
+                return obj->pluginTest->NPP_SetWindow(window);
+                       ^~~~~~~~~~~~~~~
+            2 warnings generated.
+
+        * DumpRenderTree/TestNetscapePlugIn/main.cpp:
+        (CRASH): Use __builtin_trap() for gcc/clang.
+        (NPP_SetWindow): Add early return if obj is nullptr.
+
 2015-12-03  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GTK] Test /webkit2/WebKitWebResource/get-data is flaky
index d7736bc..6a7303f 100644 (file)
@@ -41,10 +41,17 @@ extern "C" void GlobalToLocal(Point*);
 
 using namespace std;
 
+#if defined(__GNUC__)
+#define CRASH() do { \
+    *(int *)(uintptr_t)0xbbadbeef = 0; \
+    __builtin_trap(); /* More reliable, but doesn't say BBADBEEF. */ \
+} while (false)
+#else
 #define CRASH() do { \
     *(int *)(uintptr_t)0xbbadbeef = 0; \
     ((void(*)())0)(); /* More reliable, but doesn't say BBADBEEF */ \
-} while(false)
+} while (false)
+#endif
 
 static bool getEntryPointsWasCalled;
 static bool initializeWasCalled;
@@ -349,29 +356,30 @@ NPError NPP_SetWindow(NPP instance, NPWindow *window)
 {
     PluginObject* obj = static_cast<PluginObject*>(instance->pdata);
 
-    if (obj) {
-        obj->lastWindow = *window;
+    if (!obj)
+        return NPERR_GENERIC_ERROR;
 
-        if (obj->logSetWindow) {
-            pluginLog(instance, "NPP_SetWindow: %d %d", (int)window->width, (int)window->height);
-            obj->logSetWindow = FALSE;
-            executeScript(obj, "testRunner.notifyDone();");
-        }
+    obj->lastWindow = *window;
 
-        if (obj->onSetWindow)
-            executeScript(obj, obj->onSetWindow);
+    if (obj->logSetWindow) {
+        pluginLog(instance, "NPP_SetWindow: %d %d", (int)window->width, (int)window->height);
+        obj->logSetWindow = FALSE;
+        executeScript(obj, "testRunner.notifyDone();");
+    }
 
-        if (obj->testWindowOpen) {
-            testWindowOpen(instance);
-            obj->testWindowOpen = FALSE;
-        }
+    if (obj->onSetWindow)
+        executeScript(obj, obj->onSetWindow);
 
-        if (obj->testKeyboardFocusForPlugins) {
-            obj->eventLogging = true;
-            executeScript(obj, "eventSender.keyDown('A');");
-        }
+    if (obj->testWindowOpen) {
+        testWindowOpen(instance);
+        obj->testWindowOpen = FALSE;
     }
-    
+
+    if (obj->testKeyboardFocusForPlugins) {
+        obj->eventLogging = true;
+        executeScript(obj, "eventSender.keyDown('A');");
+    }
+
     return obj->pluginTest->NPP_SetWindow(window);
 }