From 586e6deefd4c8bcf7f904246a68063c1199865a1 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Fri, 7 Jun 2024 22:44:49 +0200 Subject: Ensure the same number of tags for CSS and HTML The Tags array can be modified without changing the "ntags" number in the CSS side. To prevent errors, an static assert ensures the same number is used in both sides, which is known at compilation time. Fixes: https://github.com/dillo-browser/dillo/issues/184 --- src/css.hh | 20 ++++++++++++++------ src/html.cc | 2 ++ src/html.hh | 16 ++++++++++++++++ 3 files changed, 32 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/css.hh b/src/css.hh index 011c17f8..44328c42 100644 --- a/src/css.hh +++ b/src/css.hh @@ -1,8 +1,21 @@ +/* + * File: css.hh + * + * Copyright (C) 2008-2014 Johannes Hofmann + * Copyright (C) 2024 Rodrigo Arias Mallo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + */ + #ifndef __CSS_HH__ #define __CSS_HH__ #include "dw/core.hh" #include "doctree.hh" +#include "html.hh" /* Origin and weight. Used only internally.*/ typedef enum { @@ -482,12 +495,7 @@ class CssStyleSheet { (true, true, 256) {}; }; - static const int ntags = 90 + 14; // \todo don't hardcode - /* 90 is the full number of html4 elements, including those which we have - * implemented. From html5, let's add: article, header, footer, mark, - * nav, section, aside, figure, figcaption, wbr, audio, video, source, - * embed. - */ + static const int ntags = HTML_NTAGS; RuleList elementTable[ntags], anyTable; RuleMap idTable, classTable; diff --git a/src/html.cc b/src/html.cc index c0d4d388..323b7b1e 100644 --- a/src/html.cc +++ b/src/html.cc @@ -3555,6 +3555,8 @@ static const TagInfo Tags[] = { }; #define NTAGS (sizeof(Tags)/sizeof(Tags[0])) +static_assert(NTAGS == HTML_NTAGS, + "Mismatch between number of tags in Tags and HTML_NTAGS"); /* * Compares tag from buffer ('/' or '>' or space-ended string) [p1] diff --git a/src/html.hh b/src/html.hh index 5b18c1a8..ef1187ff 100644 --- a/src/html.hh +++ b/src/html.hh @@ -1,3 +1,15 @@ +/* + * File: html.hh + * + * Copyright (C) 2005-2009 Jorge Arellano Cid + * Copyright (C) 2024 Rodrigo Arias Mallo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + */ + #ifndef __HTML_HH__ #define __HTML_HH__ @@ -7,6 +19,10 @@ extern "C" { #endif /* __cplusplus */ +/* Keep in sync with the length of the Tags array. It is protected by an + * static assert in html.cc to prevent errors) */ +#define HTML_NTAGS 93 + /* * Exported functions */ -- cgit v1.2.3