The function string_desc_new_addr is currently documented in section "Memory-allocating operations on string descriptors". But in fact, it does not allocate memory.
This patch fixes it. 2024-10-13 Bruno Haible <br...@clisp.org> string-desc: Fix categorization string_desc_new_addr. * lib/string-desc.h (string_desc_new_addr): Move to section "Side-effect-free operations". * lib/string-desc.c (string_desc_new_addr): Move accordingly. diff --git a/lib/string-desc.c b/lib/string-desc.c index 17856d9554..58a87e1220 100644 --- a/lib/string-desc.c +++ b/lib/string-desc.c @@ -119,6 +119,20 @@ string_desc_new_empty (void) } +string_desc_t +string_desc_new_addr (idx_t n, char *addr) +{ + string_desc_t result; + + result._nbytes = n; + if (n == 0) + result._data = NULL; + else + result._data = addr; + + return result; +} + string_desc_t string_desc_from_c (const char *s) { @@ -191,20 +205,6 @@ string_desc_new (string_desc_t *resultp, idx_t n) return 0; } -string_desc_t -string_desc_new_addr (idx_t n, char *addr) -{ - string_desc_t result; - - result._nbytes = n; - if (n == 0) - result._data = NULL; - else - result._data = addr; - - return result; -} - int string_desc_new_filled (string_desc_t *resultp, idx_t n, char c) { diff --git a/lib/string-desc.h b/lib/string-desc.h index e5c969ca83..ff9c86d6a0 100644 --- a/lib/string-desc.h +++ b/lib/string-desc.h @@ -117,6 +117,9 @@ extern ptrdiff_t string_desc_contains (string_desc_t haystack, string_desc_t nee /* Return an empty string. */ extern string_desc_t string_desc_new_empty (void); +/* Construct and return a string of length N, at the given memory address. */ +extern string_desc_t string_desc_new_addr (idx_t n, char *addr); + /* Return a string that represents the C string S, of length strlen (S). */ extern string_desc_t string_desc_from_c (const char *s); @@ -146,9 +149,6 @@ extern int string_desc_fwrite (FILE *fp, string_desc_t s); _GL_ATTRIBUTE_NODISCARD extern int string_desc_new (string_desc_t *resultp, idx_t n); -/* Construct and return a string of length N, at the given memory address. */ -extern string_desc_t string_desc_new_addr (idx_t n, char *addr); - /* Construct a string of length N, filled with C. Return 0 if successful. Upon error, return -1 with errno set. */