From ae51f22dafb65d962bd358b1df8aa928fbfb45a0 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Mon, 15 Nov 2021 18:10:33 -0800 Subject: [PATCH] mkFont: make it more obvious to the compiler the extent of 'flags' All calls to this function use literals that fit in an unsigned char. Squashes a -Wconversion warning. This also introduces a new header constant, `GV_TEXTFONT_FLAGS_WIDTH`. --- lib/common/htmllex.c | 7 ++++--- lib/common/textspan.h | 9 ++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/common/htmllex.c b/lib/common/htmllex.c index e0ac02a42..289f5892e 100644 --- a/lib/common/htmllex.c +++ b/lib/common/htmllex.c @@ -581,12 +581,13 @@ static htmlimg_t *mkImg(char **atts) return img; } -static textfont_t *mkFont(GVC_t *gvc, char **atts, int flags) -{ +static textfont_t *mkFont(GVC_t *gvc, char **atts, unsigned char flags) { textfont_t tf = {NULL,NULL,NULL,0.0,0,0}; tf.size = -1.0; /* unassigned */ - tf.flags = flags; + enum { FLAGS_MAX = (1 << GV_TEXTFONT_FLAGS_WIDTH) - 1 }; + assert(flags <= FLAGS_MAX); + tf.flags = (unsigned char)(flags & FLAGS_MAX); if (atts) doAttrs(&tf, font_items, sizeof(font_items) / ISIZE, atts, ""); diff --git a/lib/common/textspan.h b/lib/common/textspan.h index 22deeb45c..394b5b043 100644 --- a/lib/common/textspan.h +++ b/lib/common/textspan.h @@ -14,8 +14,10 @@ extern "C" { #endif +#define GV_TEXTFONT_FLAGS_WIDTH 7 + /* Bold, Italic, Underline, Sup, Sub, Strike */ -/* Stored in textfont_t.flags, which is 7 bits, so full */ +/* Stored in textfont_t.flags, which is GV_TEXTFONT_FLAGS_WIDTH bits, so full */ /* Probably should be moved to textspan_t */ #define HTML_BF (1 << 0) #define HTML_IF (1 << 1) @@ -46,8 +48,9 @@ extern "C" { char* color; PostscriptAlias *postscript_alias; double size; - unsigned int flags:7; /* HTML_UL, HTML_IF, HTML_BF, etc. */ - unsigned int cnt:(sizeof(unsigned int) * 8 - 7); /* reference count */ + unsigned int flags:GV_TEXTFONT_FLAGS_WIDTH; // HTML_UL, HTML_IF, HTML_BF, etc. + unsigned int cnt:(sizeof(unsigned int) * 8 - GV_TEXTFONT_FLAGS_WIDTH); + ///< reference count } textfont_t; /* atomic unit of text emitted using a single htmlfont_t */ -- 2.40.0