From c6b411daead333365a0524ce5518daf186107684 Mon Sep 17 00:00:00 2001 From: Lars Kanis <lars@greiz-reinsdorf.de> Date: Fri, 1 Jun 2012 00:22:35 +0200 Subject: [PATCH] Avoid Segfauls in lots of methods when called with nil instead of FXApp, FXComposite or FXWindow objects --- swig-interfaces/FXApp.i | 2 +- swig-interfaces/FXSplashWindow.i | 4 ++-- swig-interfaces/ruby-typemaps.i | 10 ++++++++-- test/TC_FXApp.rb | 4 ++++ test/TC_FXButton.rb | 4 ++++ test/TC_FXGLViewer.rb | 9 +++++++++ test/TC_FXMessageBox.rb | 4 ++++ test/TC_FXScrollArea.rb | 4 ++++ test/TC_FXShell.rb | 4 ++++ test/TC_FXTopWindow.rb | 4 ++++ 10 files changed, 44 insertions(+), 5 deletions(-) diff --git a/swig-interfaces/FXApp.i b/swig-interfaces/FXApp.i index 0889ebc..89f7d79 100644 --- a/swig-interfaces/FXApp.i +++ b/swig-interfaces/FXApp.i @@ -464,7 +464,7 @@ public: * Run popup menu while shown, until stop() or stopModal() is called. * Also returns when entering previous cascading popup menu. */ - FXint runPopup(FXWindow* window); + FXint runPopup(FXWindow* owner); /// True if the window is modal bool isModal(FXWindow* window) const; diff --git a/swig-interfaces/FXSplashWindow.i b/swig-interfaces/FXSplashWindow.i index 79f671f..02c59cf 100644 --- a/swig-interfaces/FXSplashWindow.i +++ b/swig-interfaces/FXSplashWindow.i @@ -53,10 +53,10 @@ public: public: /// Construct splash window - FXSplashWindow(FXApp* ap,FXIcon* ic,FXuint opts=SPLASH_SIMPLE,FXuint ms=5000); + FXSplashWindow(FXApp* a,FXIcon* ic,FXuint opts=SPLASH_SIMPLE,FXuint ms=5000); /// Construct splash window - FXSplashWindow(FXWindow* ow,FXIcon* ic,FXuint opts=SPLASH_SIMPLE,FXuint ms=5000); + FXSplashWindow(FXWindow* own,FXIcon* ic,FXuint opts=SPLASH_SIMPLE,FXuint ms=5000); /// Set the icon for the splash window void setIcon(FXIcon* ic); diff --git a/swig-interfaces/ruby-typemaps.i b/swig-interfaces/ruby-typemaps.i index d59085d..109aee5 100644 --- a/swig-interfaces/ruby-typemaps.i +++ b/swig-interfaces/ruby-typemaps.i @@ -24,8 +24,14 @@ %apply Pointer NONNULL { FXApp* APP, - FXComposite* PARENT, - FXWindow* OWNER + FXApp* a, + FXApp* app, + FXApp* application, + FXComposite* PARENT, + FXComposite* p, + FXWindow* OWNER, + FXWindow* own, + FXWindow* owner } /* Type-checking rules */ diff --git a/test/TC_FXApp.rb b/test/TC_FXApp.rb index 555e41c..7501017 100755 --- a/test/TC_FXApp.rb +++ b/test/TC_FXApp.rb @@ -23,6 +23,10 @@ class TC_FXApp2 < Fox::TestCase super(self.class.name) end + def test_nil_window_raises_argument_error + assert_raise(ArgumentError){ app.runPopup(nil) } + end + def check_events(pipe_rd, pipe_wr) app.addInput(pipe_wr, INPUT_WRITE, app, FXApp::ID_QUIT) app.run diff --git a/test/TC_FXButton.rb b/test/TC_FXButton.rb index bd0127b..425076c 100755 --- a/test/TC_FXButton.rb +++ b/test/TC_FXButton.rb @@ -10,6 +10,10 @@ class TC_FXButton < Fox::TestCase @button = FXButton.new(mainWindow, "buttonText") end + def test_nil_parent_raises_argument_error + assert_raise(ArgumentError){ FXButton.new(nil, "buttonText") } + end + def testText assert(@button.text) assert_instance_of(String, @button.text) diff --git a/test/TC_FXGLViewer.rb b/test/TC_FXGLViewer.rb index 36fd5ad..dede2a4 100755 --- a/test/TC_FXGLViewer.rb +++ b/test/TC_FXGLViewer.rb @@ -10,6 +10,15 @@ class TC_FXGLViewer < Fox::TestCase vis = FXGLVisual.new(app, VISUAL_DOUBLEBUFFER) @viewer = FXGLViewer.new(mainWindow, vis) end + + def test_supported + assert FXGLVisual.supported?(app) + end + + def test_nil_app_raises_argument_error + assert_raise(ArgumentError){ FXGLVisual.supported?(nil) } + end + =begin def test_readPixels pixels = @viewer.readPixels(0, 0, @viewer.width, @viewer.height) diff --git a/test/TC_FXMessageBox.rb b/test/TC_FXMessageBox.rb index 372d2b1..dfc9e21 100755 --- a/test/TC_FXMessageBox.rb +++ b/test/TC_FXMessageBox.rb @@ -9,6 +9,10 @@ class TC_FXMessageBox < Fox::TestCase super(self.class.name) end + def test_nil_app_raises_argument_error + assert_raise(ArgumentError){ FXMessageBox.new(nil, "Save?", "Save?", :opts => MBOX_SAVE_CANCEL_DONTSAVE) } + end + def test_construct_with_save_cancel_dontsave assert_nothing_raised(RangeError) do FXMessageBox.new(mainWindow, "Save?", "Save?", :opts => MBOX_SAVE_CANCEL_DONTSAVE) diff --git a/test/TC_FXScrollArea.rb b/test/TC_FXScrollArea.rb index 23546cb..1c549e9 100755 --- a/test/TC_FXScrollArea.rb +++ b/test/TC_FXScrollArea.rb @@ -10,6 +10,10 @@ class TC_FXScrollArea < Fox::TestCase @scrollArea = FXScrollArea.new(mainWindow) end + def test_nil_parent_raises_argument_error + assert_raise(ArgumentError){ FXScrollArea.new(nil) } + end + def test_position_get pos = @scrollArea.position assert_instance_of(Array, pos) diff --git a/test/TC_FXShell.rb b/test/TC_FXShell.rb index 08be543..89391aa 100755 --- a/test/TC_FXShell.rb +++ b/test/TC_FXShell.rb @@ -15,6 +15,10 @@ class TC_FXShell < Test::Unit::TestCase @mainWin = FXMainWindow.new(@app, 'TC_FXShell') end + def test_nil_parent_raises_argument_error + assert_raise(ArgumentError){ FXShell.new(nil, 0, 0, 0, 0, 0) } + end + def test_new # Free-floating shell1 = FXShell.new(@app, 0, 0, 0, 0, 0) diff --git a/test/TC_FXTopWindow.rb b/test/TC_FXTopWindow.rb index 022897b..97eb690 100755 --- a/test/TC_FXTopWindow.rb +++ b/test/TC_FXTopWindow.rb @@ -15,6 +15,10 @@ class TC_FXTopWindow < Test::Unit::TestCase @mainWin = FXMainWindow.new(@app, 'TC_FXButton') end + def test_nil_app_raises_argument_error + assert_raise(ArgumentError){ FXTopWindow.new(nil, 'TC_FXButton') } + end + def test_new # Free-floating top1 = FXTopWindow.new(@app, "top1", nil, nil, DECOR_ALL, 0, 0, 0, 0, -- GitLab