From 8999a195934f8a59fe2b1faae5d54678e1e93fd8 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Mon, 17 Jan 2022 17:07:46 +0100 Subject: [PATCH] [cast] Explicit casts for narrowing conversions --- src/document/dom/renderer.c | 2 +- src/document/renderer.c | 2 +- src/dom/configuration.c | 2 +- src/dom/node.c | 2 +- src/dom/scanner.c | 2 +- src/dom/sgml/parser.c | 2 +- src/ecmascript/ecmascript.c | 2 +- src/terminal/color.c | 6 +++--- src/terminal/kbd.h | 2 +- src/util/conv.c | 2 +- src/viewer/text/link.c | 2 +- 11 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/document/dom/renderer.c b/src/document/dom/renderer.c index 9086fcd12..b73a84fba 100644 --- a/src/document/dom/renderer.c +++ b/src/document/dom/renderer.c @@ -89,7 +89,7 @@ render_dom_document(struct cache_entry *cached, struct document *document, enum sgml_parser_type parser_type; char *string = struri(cached->uri); size_t length = strlen(string); - struct dom_string uri = INIT_DOM_STRING(string, length); + struct dom_string uri = INIT_DOM_STRING(string, (unsigned int)length); convert_table = get_convert_table(head, document->options.cp, document->options.assume_cp, diff --git a/src/document/renderer.c b/src/document/renderer.c index a26575199..a6e3dc844 100644 --- a/src/document/renderer.c +++ b/src/document/renderer.c @@ -206,7 +206,7 @@ process_snippets(struct ecmascript_interpreter *interpreter, fragment = get_cache_fragment(cached); if (fragment) { - struct string code = INIT_STRING(fragment->data, fragment->length); + struct string code = INIT_STRING(fragment->data, (int)fragment->length); ecmascript_eval(interpreter, &code, NULL); } diff --git a/src/dom/configuration.c b/src/dom/configuration.c index 857b18214..e17b5de15 100644 --- a/src/dom/configuration.c +++ b/src/dom/configuration.c @@ -334,7 +334,7 @@ parse_dom_config(char *flaglist, char separator) while (flaglist) { char *end = separator ? strchr((const char *)flaglist, separator) : NULL; int length = end ? end - flaglist : strlen(flaglist); - struct dom_string name = INIT_DOM_STRING(flaglist, length); + struct dom_string name = INIT_DOM_STRING(flaglist, (unsigned int)length); flags |= get_dom_config_flag(&name); if (end) end++; diff --git a/src/dom/node.c b/src/dom/node.c index e7e718c4a..97a75a5e4 100644 --- a/src/dom/node.c +++ b/src/dom/node.c @@ -129,7 +129,7 @@ struct dom_node_search { }; #define INIT_DOM_NODE_SEARCH(key, list) \ - { (key), -1, 0, (list)->size, } + { (key), -1, 0, (int)(list)->size, } int dom_node_casecmp(struct dom_node *node1, struct dom_node *node2) diff --git a/src/dom/scanner.c b/src/dom/scanner.c index 764355a98..2a03e33c8 100644 --- a/src/dom/scanner.c +++ b/src/dom/scanner.c @@ -19,7 +19,7 @@ map_dom_scanner_string(struct dom_scanner *scanner, char *ident, char *end, int base_type) { const struct dom_scanner_string_mapping *mappings = scanner->info->mappings; - struct dom_string name = INIT_DOM_STRING(ident, end - ident); + struct dom_string name = INIT_DOM_STRING(ident, (unsigned int)(end - ident)); for (; is_dom_string_set(&mappings->name); mappings++) { if (mappings->base_type == base_type diff --git a/src/dom/sgml/parser.c b/src/dom/sgml/parser.c index e0c45a6b1..a0af0d1be 100644 --- a/src/dom/sgml/parser.c +++ b/src/dom/sgml/parser.c @@ -427,7 +427,7 @@ enum dom_code parse_sgml(struct sgml_parser *parser, char *buf, size_t bufsize, int complete) { - struct dom_string source = INIT_DOM_STRING(buf, bufsize); + struct dom_string source = INIT_DOM_STRING(buf, (unsigned int)bufsize); struct dom_node *node; if (complete) diff --git a/src/ecmascript/ecmascript.c b/src/ecmascript/ecmascript.c index 023eb882f..4ef5d013d 100644 --- a/src/ecmascript/ecmascript.c +++ b/src/ecmascript/ecmascript.c @@ -463,7 +463,7 @@ void ecmascript_protocol_handler(struct session *ses, struct uri *uri) { struct document_view *doc_view = current_frame(ses); - struct string current_url = INIT_STRING(struri(uri), strlen(struri(uri))); + struct string current_url = INIT_STRING(struri(uri), (int)strlen(struri(uri))); char *redirect_url, *redirect_abs_url; struct uri *redirect_uri; diff --git a/src/terminal/color.c b/src/terminal/color.c index 9e23b5ca8..7f42648c4 100644 --- a/src/terminal/color.c +++ b/src/terminal/color.c @@ -39,9 +39,9 @@ color_distance(const struct rgb *c1, const struct rgb *c2) #define GREEN_COLOR_MASK 0x0000FF00 #define BLUE_COLOR_MASK 0x000000FF -#define RED_COLOR(color) (((color) & RED_COLOR_MASK) >> 16) -#define GREEN_COLOR(color) (((color) & GREEN_COLOR_MASK) >> 8) -#define BLUE_COLOR(color) (((color) & BLUE_COLOR_MASK) >> 0) +#define RED_COLOR(color) (unsigned char)(((color) & RED_COLOR_MASK) >> 16) +#define GREEN_COLOR(color) (unsigned char)(((color) & GREEN_COLOR_MASK) >> 8) +#define BLUE_COLOR(color) (unsigned char)(((color) & BLUE_COLOR_MASK) >> 0) #define RED(color) (RED_COLOR(color) << 3) #define GREEN(color) (GREEN_COLOR(color) << 2) diff --git a/src/terminal/kbd.h b/src/terminal/kbd.h index b22ad6e64..f8f0c2a8a 100644 --- a/src/terminal/kbd.h +++ b/src/terminal/kbd.h @@ -142,7 +142,7 @@ void kbd_ctrl_c(void); int is_blocked(void); void get_terminal_name(char[MAX_TERM_LEN]); -#define kbd_get_key(kbd_) ((kbd_)->key) +#define kbd_get_key(kbd_) (char)((kbd_)->key) #define kbd_key_is(kbd_, key) (kbd_get_key(kbd_) == (key)) #define kbd_get_modifier(kbd_) ((kbd_)->modifier) diff --git a/src/util/conv.c b/src/util/conv.c index 144706d36..5f1563b54 100644 --- a/src/util/conv.c +++ b/src/util/conv.c @@ -424,7 +424,7 @@ strtolx(char *str, char **end) int month2num(const char *str) { - char month[3] = { str[0]|32, str[1]|32, str[2]|32 }; + char month[3] = { (char)(str[0]|32), (char)(str[1]|32), (char)(str[2]|32) }; switch (month[0]) { case 'j': /* jan, jun, jul */ diff --git a/src/viewer/text/link.c b/src/viewer/text/link.c index 2072072b4..5a201a5d5 100644 --- a/src/viewer/text/link.c +++ b/src/viewer/text/link.c @@ -71,7 +71,7 @@ current_link_evhook(struct document_view *doc_view, enum script_event_hook_type while ((ret = strstr((const char *)ret, "return "))) while (*ret != ' ') *ret++ = ' '; { - struct string src = INIT_STRING(evhook->src, strlen(evhook->src)); + struct string src = INIT_STRING(evhook->src, (int)strlen(evhook->src)); /* TODO: Some even handlers return a bool. */ if (!ecmascript_eval_boolback(doc_view->vs->ecmascript, &src)) return 0;