From 2ca70f50934ff29a7568e48e8a64cc7b9b8ab51b Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Fri, 2 Feb 2018 12:59:35 +0100 Subject: [PATCH] Workaround a crash in BDirectWindow management. --- media-libs/libsdl2/libsdl2-2.0.7.recipe | 2 +- .../libsdl2/patches/libsdl2-2.0.7.patchset | 58 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/media-libs/libsdl2/libsdl2-2.0.7.recipe b/media-libs/libsdl2/libsdl2-2.0.7.recipe index ed28de65b..91f520b22 100644 --- a/media-libs/libsdl2/libsdl2-2.0.7.recipe +++ b/media-libs/libsdl2/libsdl2-2.0.7.recipe @@ -6,7 +6,7 @@ software, emulators, and popular games." HOMEPAGE="http://www.libsdl.org/" COPYRIGHT="1997-2017 Sam Lantinga" LICENSE="Zlib" -REVISION="2" +REVISION="3" SOURCE_URI="http://www.libsdl.org/release/SDL2-$portVersion.tar.gz" CHECKSUM_SHA256="ee35c74c4313e2eda104b14b1b86f7db84a04eeab9430d56e001cea268bf4d5e" SOURCE_DIR="SDL2-$portVersion" diff --git a/media-libs/libsdl2/patches/libsdl2-2.0.7.patchset b/media-libs/libsdl2/patches/libsdl2-2.0.7.patchset index f5c25d85f..87b5fedf5 100644 --- a/media-libs/libsdl2/patches/libsdl2-2.0.7.patchset +++ b/media-libs/libsdl2/patches/libsdl2-2.0.7.patchset @@ -148,3 +148,61 @@ index c77e630..ffb09bb 100644 -- 2.15.1 + +From b15465c0835d6e998b6255a7654d14fb7b8b030d Mon Sep 17 00:00:00 2001 +From: Adrien Destugues +Date: Fri, 2 Feb 2018 10:40:00 +0100 +Subject: Fix crash when opening window + +- _num_clips was not set in constructor, so a NULL _clips could be + mistakenly dereferenced. +- As _clips is accessible outside the class, it is not a good idea to + free/reallocate it. Try to limit this by reallocating only when it needs to + grow. + +diff --git a/src/video/haiku/SDL_BWin.h b/src/video/haiku/SDL_BWin.h +index a20147a..105ebb5 100644 +--- a/src/video/haiku/SDL_BWin.h ++++ b/src/video/haiku/SDL_BWin.h +@@ -86,6 +86,7 @@ class SDL_BWin:public BDirectWindow + _buffer_locker = new BLocker(); + _bitmap = NULL; + _clips = NULL; ++ _num_clips = 0; + + #ifdef DRAWTHREAD + _draw_thread_id = spawn_thread(BE_DrawThread, "drawing_thread", +@@ -179,13 +180,17 @@ class SDL_BWin:public BDirectWindow + _connected = true; + + case B_DIRECT_MODIFY: +- if(_clips) { +- free(_clips); +- _clips = NULL; ++ if (info->clip_list_count > _num_clips) ++ { ++ if(_clips) { ++ free(_clips); ++ _clips = NULL; ++ } + } + + _num_clips = info->clip_list_count; +- _clips = (clipping_rect *)malloc(_num_clips*sizeof(clipping_rect)); ++ if (_clips == NULL) ++ _clips = (clipping_rect *)malloc(_num_clips*sizeof(clipping_rect)); + if(_clips) { + memcpy(_clips, info->clip_list, + _num_clips*sizeof(clipping_rect)); +@@ -652,7 +657,7 @@ private: + clipping_rect _bounds; + BLocker *_buffer_locker; + clipping_rect *_clips; +- int32 _num_clips; ++ uint32 _num_clips; + int32 _bytes_per_px; + thread_id _draw_thread_id; + +-- +2.15.1 +