]> git.saurik.com Git - wxWidgets.git/commitdiff
Fix crash in wxWebKitCtrl when using JavaScript.
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 29 Sep 2010 13:46:24 +0000 (13:46 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 29 Sep 2010 13:46:24 +0000 (13:46 +0000)
Ignore the unknown types of the script result, in particular don't crash
trying to dereference an uninitialized pointer if the script didn't return
anything.

Closes #12361.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65673 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/html/htmlctrl/webkit/webkit.mm

index 6f6ecbc8456797a93c984cb19eeaeb2b2f602ff8..9a79c6ab08c0314c409566c5d195f023edac2dd9 100644 (file)
@@ -684,7 +684,6 @@ wxString wxWebKitCtrl::RunScript(const wxString& javascript){
     id result = [[m_webView windowScriptObject] evaluateWebScript:(NSString*)wxNSStringWithWxString( javascript )];
 
     NSString* resultAsString;
-    wxString resultAsWxString = wxEmptyString;
     NSString* className = NSStringFromClass([result class]);
     if ([className isEqualToString:@"NSCFNumber"])
         resultAsString = [NSString stringWithFormat:@"%@", result];
@@ -699,10 +698,9 @@ wxString wxWebKitCtrl::RunScript(const wxString& javascript){
     else if ([className isEqualToString:@"WebScriptObject"])
         resultAsString = [result stringRepresentation];
     else
-        fprintf(stderr, "wxWebKitCtrl::RunScript - Unexpected return type: %s!\n", [className UTF8String]);
+        return wxString(); // This can happen, see e.g. #12361.
 
-    resultAsWxString = wxStringWithNSString( resultAsString );
-    return resultAsWxString;
+    return wxStringWithNSString( resultAsString );
 }
 
 void wxWebKitCtrl::OnSize(wxSizeEvent &event){