disallow NULL for cx_str() and cx_mutstr()

Tue, 13 Sep 2022 20:11:26 +0200

author
Mike Becker <universe@uap-core.de>
date
Tue, 13 Sep 2022 20:11:26 +0200
changeset 584
184e9ebfc3cc
parent 583
0f3c9662f9b5
child 585
038f5e99e00f

disallow NULL for cx_str() and cx_mutstr()

src/cx/string.h file | annotate | diff | comparison | revisions
--- a/src/cx/string.h	Fri Sep 09 20:19:08 2022 +0200
+++ b/src/cx/string.h	Tue Sep 13 20:11:26 2022 +0200
@@ -96,19 +96,18 @@
  * Wraps a mutable string that must be zero-terminated.
  *
  * The length is implicitly inferred by using a call to \c strlen().
- * As a special case, a \c NULL argument is treated like an empty string.
  *
  * \note the wrapped string will share the specified pointer to the string.
  * If you do want a copy, use cx_strdup() on the return value of this function.
  *
  * If you need to wrap a constant string, use cx_str().
  *
- * @param cstring the string to wrap, must be zero-terminated (or \c NULL)
+ * @param cstring the string to wrap, must be zero-terminated
  * @return the wrapped string
  *
  * @see cx_mutstrn()
  */
-__attribute__((__warn_unused_result__))
+__attribute__((__warn_unused_result__, __nonnull__))
 cxmutstr cx_mutstr(char *cstring);
 
 /**
@@ -121,7 +120,7 @@
  *
  * If you need to wrap a constant string, use cx_strn().
  *
- * @param cstring  the string to wrap (or \c NULL, if the length is zero)
+ * @param cstring  the string to wrap (or \c NULL, only if the length is zero)
  * @param length   the length of the string
  * @return the wrapped string
  *
@@ -137,19 +136,18 @@
  * Wraps a string that must be zero-terminated.
  *
  * The length is implicitly inferred by using a call to \c strlen().
- * As a special case, a \c NULL argument is treated like an empty string.
  *
  * \note the wrapped string will share the specified pointer to the string.
  * If you do want a copy, use cx_strdup() on the return value of this function.
  *
  * If you need to wrap a non-constant string, use cx_mutstr().
  *
- * @param cstring the string to wrap, must be zero-terminated (or \c NULL)
+ * @param cstring the string to wrap, must be zero-terminated
  * @return the wrapped string
  *
  * @see cx_strn()
  */
-__attribute__((__warn_unused_result__))
+__attribute__((__warn_unused_result__, __nonnull__))
 cxstring cx_str(char const *cstring);
 
 
@@ -163,7 +161,7 @@
  *
  * If you need to wrap a non-constant string, use cx_mutstrn().
  *
- * @param cstring  the string to wrap (or \c NULL, if the length is zero)
+ * @param cstring  the string to wrap (or \c NULL, only if the length is zero)
  * @param length   the length of the string
  * @return the wrapped string
  *

mercurial