]> gitweb.michael.orlitzky.com - libsvgtiny.git/commitdiff
src/svgtiny_css.c: handle DOM_NO_MEM_ERR when setting user data
authorMichael Orlitzky <michael@orlitzky.com>
Sat, 19 Oct 2024 21:43:44 +0000 (17:43 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Sun, 20 Oct 2024 21:40:11 +0000 (17:40 -0400)
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.

src/svgtiny_css.c

index 7d52ffa14df7cc11e808df741daa0f3f3db73826..4856ac3f7bdefe4856f4bbf49415b6bf2c796415 100644 (file)
@@ -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;
 }