spv-light-decoder: Avoid GCC 11.x warning in decode_spvlb_halign().
[pspp] / src / libpspp / intern.c
index fe0e784cda6b02db4e28e54a7fdce3eb04e08cd3..b8eb5198b4d9ac902ef2ce67c2fd1c994b5f0de2 100644 (file)
@@ -77,9 +77,17 @@ intern_new (const char *s)
   return is->string;
 }
 
+const char *
+intern_new_if_nonnull (const char *s)
+{
+  return s ? intern_new (s) : NULL;
+}
+
+
 static struct interned_string *
-interned_string_from_string (const char *s)
+interned_string_from_string (const char *s_)
 {
+  char (*s)[1] = (char (*)[1]) s_;
   struct interned_string *is = UP_CAST (s, struct interned_string, string);
   assert (is->ref_cnt > 0);
   return is;
@@ -95,17 +103,26 @@ intern_ref (const char *s)
   return s;
 }
 
+const char *
+intern_ref_if_nonnull (const char *s)
+{
+  return s ? intern_ref (s) : NULL;
+}
+
 /* Decreases the reference count on S, which must be an interned string
    returned by intern_new().  If the reference count reaches 0, frees the
    interned string. */
 void
 intern_unref (const char *s)
 {
-  struct interned_string *is = interned_string_from_string (s);
-  if (--is->ref_cnt == 0)
+  if (s)
     {
-      hmap_delete (&interns, &is->node);
-      free (is);
+      struct interned_string *is = interned_string_from_string (s);
+      if (--is->ref_cnt == 0)
+        {
+          hmap_delete (&interns, &is->node);
+          free (is);
+        }
     }
 }