mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:28:11 +00:00
AK: Add trivial structure validation to SharedBuffer
If we're sharing buffers, we only want to share trivial structures as anything else could potentially share internal pointers, which most likely is going to cause problems due to different address spaces. Fix the GUI::SystemTheme structure, which was not trivial, which is now caught at compile time. Fixes #3650
This commit is contained in:
parent
87f20f704c
commit
7399874479
16 changed files with 48 additions and 29 deletions
|
@ -27,6 +27,7 @@
|
|||
#include <AK/SharedBuffer.h>
|
||||
#include <LibCore/ConfigFile.h>
|
||||
#include <LibGfx/SystemTheme.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace Gfx {
|
||||
|
||||
|
@ -49,7 +50,7 @@ int current_system_theme_buffer_id()
|
|||
void set_system_theme(SharedBuffer& buffer)
|
||||
{
|
||||
theme_buffer = buffer;
|
||||
theme_page = (SystemTheme*)theme_buffer->data();
|
||||
theme_page = theme_buffer->data<SystemTheme>();
|
||||
}
|
||||
|
||||
RefPtr<SharedBuffer> load_system_theme(const String& path)
|
||||
|
@ -57,7 +58,7 @@ RefPtr<SharedBuffer> load_system_theme(const String& path)
|
|||
auto file = Core::ConfigFile::open(path);
|
||||
auto buffer = SharedBuffer::create_with_size(sizeof(SystemTheme));
|
||||
|
||||
auto* data = (SystemTheme*)buffer->data();
|
||||
auto* data = buffer->data<SystemTheme>();
|
||||
|
||||
auto get_color = [&](auto& name) {
|
||||
auto color_string = file->read_entry("Colors", name);
|
||||
|
@ -100,7 +101,7 @@ RefPtr<SharedBuffer> load_system_theme(const String& path)
|
|||
|
||||
#undef __ENUMERATE_COLOR_ROLE
|
||||
#define __ENUMERATE_COLOR_ROLE(role) \
|
||||
data->color[(int)ColorRole::role] = get_color(#role);
|
||||
data->color[(int)ColorRole::role] = get_color(#role).value();
|
||||
ENUMERATE_COLOR_ROLES(__ENUMERATE_COLOR_ROLE)
|
||||
#undef __ENUMERATE_COLOR_ROLE
|
||||
|
||||
|
@ -111,8 +112,12 @@ RefPtr<SharedBuffer> load_system_theme(const String& path)
|
|||
DO_METRIC(TitleButtonWidth);
|
||||
DO_METRIC(TitleButtonHeight);
|
||||
|
||||
#define DO_PATH(x) \
|
||||
data->path[(int)PathRole::x] = get_path(#x, (int)PathRole::x)
|
||||
#define DO_PATH(x) \
|
||||
do { \
|
||||
auto path = get_path(#x, (int)PathRole::x); \
|
||||
memcpy(data->path[(int)PathRole::x], path, min(strlen(path) + 1, sizeof(data->path[(int)PathRole::x]))); \
|
||||
data->path[(int)PathRole::x][sizeof(data->path[(int)PathRole::x]) - 1] = '\0'; \
|
||||
} while (0)
|
||||
|
||||
DO_PATH(TitleButtonIcons);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue