From 82c1730db176a72a7efff222c68b9e38600035f8 Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Wed, 25 Jun 2025 15:39:46 +0200 Subject: [PATCH] scanner: warn on value 0 in bitfields Sometimes they're used legitimately, but in some cases they're just nonsense. For the legitimate use cases, this adds an optional "valid-zero" attribute for bitfield entries, which can be used to suppress the warning. --- protocol/wayland.dtd | 1 + protocol/wayland.xml | 4 ++-- src/scanner.c | 12 ++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/protocol/wayland.dtd b/protocol/wayland.dtd index b97372c5..62f4d778 100644 --- a/protocol/wayland.dtd +++ b/protocol/wayland.dtd @@ -24,6 +24,7 @@ + diff --git a/protocol/wayland.xml b/protocol/wayland.xml index bee74a10..7802fbb9 100644 --- a/protocol/wayland.xml +++ b/protocol/wayland.xml @@ -1084,7 +1084,7 @@ or drags initiated with other buttons than BTN_LEFT to specific actions (e.g. "ask"). - + @@ -1163,7 +1163,7 @@ use this information to adapt its behavior, e.g. choose an appropriate cursor image. - + diff --git a/src/scanner.c b/src/scanner.c index 1b71e60c..fa81c1f3 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -737,6 +737,7 @@ start_element(void *data, const char *element_name, const char **atts) const char *enumeration_name = NULL; const char *bitfield = NULL; int i, version = 0; + bool valid_zero = false; ctx->loc.line_number = XML_GetCurrentLineNumber(ctx->parser); for (i = 0; atts[i]; i += 2) { @@ -761,6 +762,14 @@ start_element(void *data, const char *element_name, const char **atts) deprecated_since = atts[i + 1]; if (strcmp(atts[i], "allow-null") == 0) allow_null = atts[i + 1]; + if (strcmp(atts[i], "valid-zero") == 0) { + if (strcmp(atts[i + 1], "true") == 0) + valid_zero = true; + else + fail(&ctx->loc, + "Invalid value for valid-zero: %s", + atts[i + 1]); + } if (strcmp(atts[i], "enum") == 0) enumeration_name = atts[i + 1]; if (strcmp(atts[i], "bitfield") == 0) @@ -914,6 +923,9 @@ start_element(void *data, const char *element_name, const char **atts) version, entry->since); entry->deprecated_since = version; + if (ctx->enumeration->bitfield && !valid_zero && strcmp(entry->value, "0") == 0) + warn(&ctx->loc, "value 0 used in a bitfield entry"); + if (summary) entry->summary = xstrdup(summary); else