summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGfx
diff options
context:
space:
mode:
authorsin-ack <sin-ack@users.noreply.github.com>2022-07-11 19:53:29 +0000
committerAndreas Kling <kling@serenityos.org>2022-07-12 23:11:35 +0200
commitc70f45ff4498fcb7ce0671e9107ecff8009d7eb2 (patch)
tree6250cc4ba6c43ed57639f3d7ff9c5fd34800989f /Userland/Libraries/LibGfx
parente3da0adfe6d278424970dad5a642bda650737e42 (diff)
downloadserenity-c70f45ff4498fcb7ce0671e9107ecff8009d7eb2.zip
Everywhere: Explicitly specify the size in StringView constructors
This commit moves the length calculations out to be directly on the StringView users. This is an important step towards the goal of removing StringView(char const*), as it moves the responsibility of calculating the size of the string to the user of the StringView (which will prevent naive uses causing OOB access).
Diffstat (limited to 'Userland/Libraries/LibGfx')
-rw-r--r--Userland/Libraries/LibGfx/Color.cpp2
-rw-r--r--Userland/Libraries/LibGfx/Font/FontStyleMapping.h3
2 files changed, 3 insertions, 2 deletions
diff --git a/Userland/Libraries/LibGfx/Color.cpp b/Userland/Libraries/LibGfx/Color.cpp
index 7d76698d9d..b5abcb8844 100644
--- a/Userland/Libraries/LibGfx/Color.cpp
+++ b/Userland/Libraries/LibGfx/Color.cpp
@@ -80,7 +80,7 @@ Optional<Color> Color::from_string(StringView string)
struct ColorAndWebName {
constexpr ColorAndWebName(ARGB32 c, char const* n)
: color(c)
- , name(n)
+ , name(n != nullptr ? StringView { n, __builtin_strlen(n) } : StringView {})
{
}
ARGB32 color;
diff --git a/Userland/Libraries/LibGfx/Font/FontStyleMapping.h b/Userland/Libraries/LibGfx/Font/FontStyleMapping.h
index 1653dd0e43..cad4e57c21 100644
--- a/Userland/Libraries/LibGfx/Font/FontStyleMapping.h
+++ b/Userland/Libraries/LibGfx/Font/FontStyleMapping.h
@@ -12,9 +12,10 @@
namespace Gfx {
struct FontStyleMapping {
+ // NOTE: __builtin_strlen required to make this work at compile time.
constexpr FontStyleMapping(int s, char const* n)
: style(s)
- , name(n)
+ , name(StringView { n, __builtin_strlen(n) })
{
}
int style { 0 };