From: Michael Orlitzky Date: Sat, 19 Oct 2024 21:43:44 +0000 (-0400) Subject: src/svgtiny_css.c: handle DOM_NO_MEM_ERR when setting user data X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=051ee66c3445a9071db366ed55cfd606cb579ec7;p=libsvgtiny.git src/svgtiny_css.c: handle DOM_NO_MEM_ERR when setting user data In set_libcss_node_data(), the dom_node_set_user_data() function can in fact return a "no memory" error. We now catch that and convert it into a CSS_NOMEM. --- diff --git a/src/svgtiny_css.c b/src/svgtiny_css.c index 7d52ffa..4856ac3 100644 --- a/src/svgtiny_css.c +++ b/src/svgtiny_css.c @@ -1980,24 +1980,30 @@ static void svgtiny_dom_user_data_handler(dom_node_operation operation, * \param node Libdom SVG node on which to store the data * \param libcss_node_data Pointer to the data to store * - * \return Always returns CSS_OK + * \return CSS_OK on success, or CSS_NOMEM on error */ css_error set_libcss_node_data(void *pw, void *node, void *libcss_node_data) { struct svgtiny_parse_state *state; void *old_data; + dom_exception err; /* A unique "userdata key" (a string) is used to identify this * data. */ state = (struct svgtiny_parse_state *)pw; - dom_node_set_user_data((dom_node *)node, - state->interned_userdata_key, - libcss_node_data, - svgtiny_dom_user_data_handler, - &old_data); + err = dom_node_set_user_data((dom_node *)node, + state->interned_userdata_key, + libcss_node_data, + svgtiny_dom_user_data_handler, + &old_data); + + if (err == DOM_NO_MEM_ERR) { + return CSS_NOMEM; + } - /* dom_node_set_user_data() always returns DOM_NO_ERR */ + /* dom_node_set_user_data() only has two return values, okay + and not-okay. */ return CSS_OK; }