aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-10-20 17:59:05 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-10-20 17:59:05 +0000
commit174f8870c75df87e4603455d8025676259fde108 (patch)
treeb16e284de14bf4d368b7c2150cf275317a891db1
parentMerge branch 'warn-not-to-use-single-letter-key-bindings-in-url-mode' (diff)
parentosc: use STRLEN() macro to make parse_rgb() more self-documenting (diff)
Merge branch 'parse-rgb-strlen'
-rw-r--r--macros.h1
-rw-r--r--meson.build1
-rw-r--r--osc.c7
3 files changed, 5 insertions, 4 deletions
diff --git a/macros.h b/macros.h
index 7cfe777e..2ecda603 100644
--- a/macros.h
+++ b/macros.h
@@ -2,6 +2,7 @@
#define PASTE(a, b) a##b
#define XPASTE(a, b) PASTE(a, b)
+#define STRLEN(str) (sizeof("" str "") - 1)
#define DO_PRAGMA(x) _Pragma(#x)
#define VERCMP(x, y, cx, cy) ((cx > x) || ((cx == x) && (cy >= y)))
diff --git a/meson.build b/meson.build
index 0ffa86f3..a03c2e75 100644
--- a/meson.build
+++ b/meson.build
@@ -158,6 +158,7 @@ vtlib = static_library(
'composed.c', 'composed.h',
'csi.c', 'csi.h',
'dcs.c', 'dcs.h',
+ 'macros.h',
'osc.c', 'osc.h',
'sixel.c', 'sixel.h',
'vt.c', 'vt.h',
diff --git a/osc.c b/osc.c
index 6d346299..ecb908ca 100644
--- a/osc.c
+++ b/osc.c
@@ -11,6 +11,7 @@
#include "base64.h"
#include "config.h"
#include "grid.h"
+#include "macros.h"
#include "notify.h"
#include "render.h"
#include "selection.h"
@@ -345,12 +346,10 @@ parse_rgb(const char *string, uint32_t *color, bool *_have_alpha,
/* Verify we have the minimum required length (for "") */
if (have_alpha) {
- /* rgba:x/x/x/x */
- if (len < 4 /* 'rgba' */ + 1 /* ':' */ + 3 /* '/' */ + 4 * 1 /* 4 * 'x' */)
+ if (len < STRLEN("rgba:x/x/x/x"))
return false;
} else {
- /* rgb:x/x/x */
- if (len < 3 /* 'rgb' */ + 1 /* ':' */ + 2 /* '/' */ + 3 * 1 /* 3 * 'x' */)
+ if (len < STRLEN("rgb:x/x/x"))
return false;
}