From eb841517222ae1d7c2beddc27a355ebf784eb349 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Tue, 18 Nov 2025 20:03:57 +0000 Subject: [PATCH 1/4] select: autogenerator: No need to NULL guard lwc_string_unref --- src/select/autogenerated_propset.h | 6 ++---- src/select/select_generator.py | 3 --- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/select/autogenerated_propset.h b/src/select/autogenerated_propset.h index c884e03..431c0f5 100644 --- a/src/select/autogenerated_propset.h +++ b/src/select/autogenerated_propset.h @@ -127,8 +127,7 @@ static inline css_error set_background_image(css_computed_style *style, uint8_t style->i.background_image = NULL; } - if (old_string != NULL) - lwc_string_unref(old_string); + lwc_string_unref(old_string); return CSS_OK; } @@ -1440,8 +1439,7 @@ static inline css_error set_list_style_image(css_computed_style *style, uint8_t style->i.list_style_image = NULL; } - if (old_string != NULL) - lwc_string_unref(old_string); + lwc_string_unref(old_string); return CSS_OK; } diff --git a/src/select/select_generator.py b/src/select/select_generator.py index f40ee4b..7619960 100644 --- a/src/select/select_generator.py +++ b/src/select/select_generator.py @@ -588,10 +588,7 @@ def make_propset_h(self): t.indent(-1) t.append('}') t.append() - t.append('if ({} != NULL)'.format(old_n)) - t.indent(1) t.append('lwc_string_unref({});'.format(old_n)) - t.indent(-1) elif v.name == 'string_arr' or v.name == 'counter_arr': iter_var = 's' if v.name == 'string_arr' else 'c' From 07b48859a265b5b088fb8a809b11433b05bc3583 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Tue, 18 Nov 2025 20:06:02 +0000 Subject: [PATCH 2/4] select: No need to NULL guard lwc_string_unref --- src/select/computed.c | 7 +- src/select/font_face.c | 10 +-- src/select/properties/background_image.c | 3 +- src/select/properties/list_style_image.c | 3 +- src/select/select.c | 14 +--- src/select/strings.c | 92 ++++++++---------------- 6 files changed, 41 insertions(+), 88 deletions(-) diff --git a/src/select/computed.c b/src/select/computed.c index 3f5b8a7..8759ede 100644 --- a/src/select/computed.c +++ b/src/select/computed.c @@ -192,11 +192,8 @@ css_error css_computed_style_destroy(css_computed_style *style) free(style->quotes); } - if (style->i.list_style_image != NULL) - lwc_string_unref(style->i.list_style_image); - - if (style->i.background_image != NULL) - lwc_string_unref(style->i.background_image); + lwc_string_unref(style->i.list_style_image); + lwc_string_unref(style->i.background_image); if (style->calc != NULL) css_calculator_unref(style->calc); diff --git a/src/select/font_face.c b/src/select/font_face.c index 07e4ef9..9788c59 100644 --- a/src/select/font_face.c +++ b/src/select/font_face.c @@ -16,9 +16,7 @@ static void font_faces_srcs_destroy(css_font_face *font_face) css_font_face_src *srcs = font_face->srcs; for (i = 0; i < font_face->n_srcs; ++i) { - if (srcs[i].location != NULL) { - lwc_string_unref(srcs[i].location); - } + lwc_string_unref(srcs[i].location); } free(srcs); @@ -69,8 +67,7 @@ css_error css__font_face_destroy(css_font_face *font_face) if (font_face == NULL) return CSS_BADPARM; - if (font_face->font_family != NULL) - lwc_string_unref(font_face->font_family); + lwc_string_unref(font_face->font_family); if (font_face->srcs != NULL) font_faces_srcs_destroy(font_face); @@ -96,8 +93,7 @@ css_error css__font_face_set_font_family(css_font_face *font_face, if (font_face == NULL || font_family == NULL) return CSS_BADPARM; - if (font_face->font_family != NULL) - lwc_string_unref(font_face->font_family); + lwc_string_unref(font_face->font_family); font_face->font_family = lwc_string_ref(font_family); diff --git a/src/select/properties/background_image.c b/src/select/properties/background_image.c index 68b1e0f..1cc629c 100644 --- a/src/select/properties/background_image.c +++ b/src/select/properties/background_image.c @@ -27,8 +27,7 @@ css_error css__set_background_image_from_hint(const css_hint *hint, error = set_background_image(style, hint->status, hint->data.string); - if (hint->data.string != NULL) - lwc_string_unref(hint->data.string); + lwc_string_unref(hint->data.string); return error; } diff --git a/src/select/properties/list_style_image.c b/src/select/properties/list_style_image.c index 7a41c3a..5a42a24 100644 --- a/src/select/properties/list_style_image.c +++ b/src/select/properties/list_style_image.c @@ -27,8 +27,7 @@ css_error css__set_list_style_image_from_hint(const css_hint *hint, error = set_list_style_image(style, hint->status, hint->data.string); - if (hint->data.string != NULL) - lwc_string_unref(hint->data.string); + lwc_string_unref(hint->data.string); return error; } diff --git a/src/select/select.c b/src/select/select.c index 4e2dedd..faea445 100644 --- a/src/select/select.c +++ b/src/select/select.c @@ -1031,17 +1031,9 @@ static void css_select__finalise_selection_state( } } - if (state->id != NULL) { - lwc_string_unref(state->id); - } - - if (state->element.ns != NULL) { - lwc_string_unref(state->element.ns); - } - - if (state->element.name != NULL){ - lwc_string_unref(state->element.name); - } + lwc_string_unref(state->id); + lwc_string_unref(state->element.ns); + lwc_string_unref(state->element.name); if (state->revert != NULL) { for (size_t i = 0; i < CSS_ORIGIN_AUTHOR; i++) { diff --git a/src/select/strings.c b/src/select/strings.c index 6e9137d..6fea61d 100644 --- a/src/select/strings.c +++ b/src/select/strings.c @@ -200,65 +200,35 @@ css_error css_select_strings_intern(css_select_strings *str) void css_select_strings_unref(css_select_strings *str) { - if (str->universal != NULL) - lwc_string_unref(str->universal); - if (str->first_child != NULL) - lwc_string_unref(str->first_child); - if (str->link != NULL) - lwc_string_unref(str->link); - if (str->visited != NULL) - lwc_string_unref(str->visited); - if (str->hover != NULL) - lwc_string_unref(str->hover); - if (str->active != NULL) - lwc_string_unref(str->active); - if (str->focus != NULL) - lwc_string_unref(str->focus); - if (str->nth_child != NULL) - lwc_string_unref(str->nth_child); - if (str->nth_last_child != NULL) - lwc_string_unref(str->nth_last_child); - if (str->nth_of_type != NULL) - lwc_string_unref(str->nth_of_type); - if (str->nth_last_of_type != NULL) - lwc_string_unref(str->nth_last_of_type); - if (str->last_child != NULL) - lwc_string_unref(str->last_child); - if (str->first_of_type != NULL) - lwc_string_unref(str->first_of_type); - if (str->last_of_type != NULL) - lwc_string_unref(str->last_of_type); - if (str->only_child != NULL) - lwc_string_unref(str->only_child); - if (str->only_of_type != NULL) - lwc_string_unref(str->only_of_type); - if (str->root != NULL) - lwc_string_unref(str->root); - if (str->empty != NULL) - lwc_string_unref(str->empty); - if (str->target != NULL) - lwc_string_unref(str->target); - if (str->lang != NULL) - lwc_string_unref(str->lang); - if (str->enabled != NULL) - lwc_string_unref(str->enabled); - if (str->disabled != NULL) - lwc_string_unref(str->disabled); - if (str->checked != NULL) - lwc_string_unref(str->checked); - if (str->first_line != NULL) - lwc_string_unref(str->first_line); - if (str->first_letter != NULL) - lwc_string_unref(str->first_letter); - if (str->before != NULL) - lwc_string_unref(str->before); - if (str->after != NULL) - lwc_string_unref(str->after); - - if (str->width != NULL) - lwc_string_unref(str->width); - if (str->height != NULL) - lwc_string_unref(str->height); - if (str->prefers_color_scheme != NULL) - lwc_string_unref(str->prefers_color_scheme); + lwc_string_unref(str->universal); + lwc_string_unref(str->first_child); + lwc_string_unref(str->link); + lwc_string_unref(str->visited); + lwc_string_unref(str->hover); + lwc_string_unref(str->active); + lwc_string_unref(str->focus); + lwc_string_unref(str->nth_child); + lwc_string_unref(str->nth_last_child); + lwc_string_unref(str->nth_of_type); + lwc_string_unref(str->nth_last_of_type); + lwc_string_unref(str->last_child); + lwc_string_unref(str->first_of_type); + lwc_string_unref(str->last_of_type); + lwc_string_unref(str->only_child); + lwc_string_unref(str->only_of_type); + lwc_string_unref(str->root); + lwc_string_unref(str->empty); + lwc_string_unref(str->target); + lwc_string_unref(str->lang); + lwc_string_unref(str->enabled); + lwc_string_unref(str->disabled); + lwc_string_unref(str->checked); + lwc_string_unref(str->first_line); + lwc_string_unref(str->first_letter); + lwc_string_unref(str->before); + lwc_string_unref(str->after); + + lwc_string_unref(str->width); + lwc_string_unref(str->height); + lwc_string_unref(str->prefers_color_scheme); } From 035b7d3122f75bc6e84750bb72e53b4fa1d1a3e1 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Tue, 18 Nov 2025 20:06:46 +0000 Subject: [PATCH 3/4] parse: No need to NULL guard lwc_string_unref --- src/parse/language.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/parse/language.c b/src/parse/language.c index 16f5d38..58bd15e 100644 --- a/src/parse/language.c +++ b/src/parse/language.c @@ -169,8 +169,7 @@ css_error css__language_destroy(css_language *language) if (language == NULL) return CSS_BADPARM; - if (language->default_namespace != NULL) - lwc_string_unref(language->default_namespace); + lwc_string_unref(language->default_namespace); if (language->namespaces != NULL) { for (i = 0; i < language->num_namespaces; i++) { @@ -855,8 +854,7 @@ css_error addNamespace(css_language *c, lwc_string *prefix, lwc_string *uri) { if (prefix == NULL) { /* Replace default namespace */ - if (c->default_namespace != NULL) - lwc_string_unref(c->default_namespace); + lwc_string_unref(c->default_namespace); /* Special case: if new namespace uri is "", use NULL */ if (lwc_string_length(uri) == 0) @@ -892,8 +890,7 @@ css_error addNamespace(css_language *c, lwc_string *prefix, lwc_string *uri) } /* Replace namespace URI */ - if (c->namespaces[idx].uri != NULL) - lwc_string_unref(c->namespaces[idx].uri); + lwc_string_unref(c->namespaces[idx].uri); /* Special case: if new namespace uri is "", use NULL */ if (lwc_string_length(uri) == 0) From 3d91796ec62811801ad0b848434306470ced3a11 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Tue, 18 Nov 2025 20:07:11 +0000 Subject: [PATCH 4/4] stylesheet: No need to NULL guard lwc_string_unref --- src/stylesheet.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/stylesheet.c b/src/stylesheet.c index 7c30a31..b17f1dd 100644 --- a/src/stylesheet.c +++ b/src/stylesheet.c @@ -854,8 +854,7 @@ css_error css__stylesheet_selector_destroy(css_stylesheet *sheet, d = c->combinator; for (detail = &c->data; detail;) { - if (detail->qname.ns != NULL) - lwc_string_unref(detail->qname.ns); + lwc_string_unref(detail->qname.ns); lwc_string_unref(detail->qname.name); if (detail->value_type == @@ -874,8 +873,7 @@ css_error css__stylesheet_selector_destroy(css_stylesheet *sheet, } for (detail = &selector->data; detail;) { - if (detail->qname.ns != NULL) - lwc_string_unref(detail->qname.ns); + lwc_string_unref(detail->qname.ns); lwc_string_unref(detail->qname.name); if (detail->value_type == CSS_SELECTOR_DETAIL_VALUE_STRING && @@ -1154,8 +1152,7 @@ css_error css__stylesheet_rule_destroy(css_stylesheet *sheet, css_rule *rule) { css_rule_import *import = (css_rule_import *) rule; - if (import->url != NULL) - lwc_string_unref(import->url); + lwc_string_unref(import->url); if (import->media != NULL) { css__mq_query_destroy(import->media);