Skip to content

Commit 6a80ca4

Browse files
authored
C: Fix hb_string_T compiler warnings (#1427)
This pull request address the following `hb_string_T` casting warnings when running `bundle exec rake compile` ``` compiling ../../../../ext/herb/../../src/parser.c ../../../../ext/herb/../../src/parser.c:322:31: warning: initializing 'char *' with an expression of type 'const char[1]' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers] 322 | ast_html_text_node_init(HB_STRING_EMPTY, start, parser->current_token->location.start, errors, parser->allocator); | ^~~~~~~~~~~~~~~ ../../../../ext/herb/../../src/include/analyze/../util/hb_string.h:18:50: note: expanded from macro 'HB_STRING_EMPTY' 18 | #define HB_STRING_EMPTY ((hb_string_T) { .data = "", .length = 0 }) | ^~ 1 warning generated. compiling ../../../../ext/herb/../../src/parser_helpers.c ../../../../ext/herb/../../src/parser_helpers.c:75:21: warning: initializing 'char *' with an expression of type 'const char[1]' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers] 75 | default: return HB_STRING_EMPTY; | ^~~~~~~~~~~~~~~ ../../../../ext/herb/../../src/include/analyze/../util/hb_string.h:18:50: note: expanded from macro 'HB_STRING_EMPTY' 18 | #define HB_STRING_EMPTY ((hb_string_T) { .data = "", .length = 0 }) | ^~ 1 warning generated. ``` ``` compiling ../../../../ext/herb/../../src/analyze/action_view/tag_helpers.c ../../../../ext/herb/../../src/analyze/action_view/tag_helpers.c:698:63: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'uint32_t' (aka 'unsigned int') [-Wshorten-64-to-32] 698 | hb_string_T raw_content = { .data = raw_copy, .length = content_length }; | ~ ^~~~~~~~~~~~~~ 1 warning generated. ```
1 parent 18a9956 commit 6a80ca4

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/analyze/action_view/tag_helpers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ static AST_NODE_T* transform_erb_block_to_tag_helper(
695695

696696
size_t content_length = end_offset - start_offset;
697697
char* raw_copy = hb_allocator_strndup(allocator, context->source + start_offset, content_length);
698-
hb_string_T raw_content = { .data = raw_copy, .length = content_length };
698+
hb_string_T raw_content = { .data = raw_copy, .length = (uint32_t) content_length };
699699

700700
AST_LITERAL_NODE_T* literal_node =
701701
ast_literal_node_init(raw_content, body_start, body_end, hb_array_init(0, allocator), allocator);

src/include/util/hb_string.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ typedef struct HB_STRING_STRUCT {
1515
uint32_t length;
1616
} hb_string_T;
1717

18-
#define HB_STRING_EMPTY ((hb_string_T) { .data = "", .length = 0 })
18+
#define HB_STRING_EMPTY ((hb_string_T) { .data = (char*) "", .length = 0 })
1919
#define HB_STRING_NULL ((hb_string_T) { .data = NULL, .length = 0 })
2020

2121
#define HB_STRING_LITERAL(string) { .data = (char*) (string), .length = (uint32_t) (sizeof(string) - 1) }

0 commit comments

Comments
 (0)