From 4115fcbc382341c4765936bb0dec40f46cb60395 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 3 May 2023 10:11:45 +1000 Subject: [PATCH] Cleanup: update, add function attributes for BLI_string & BLI_path Explicitly list ATTR_NONNULL indices in most cases so it's explicit that arguments aren't NULL (and adding new arguments that can be NULL isn't such a hassle). --- source/blender/blenlib/BLI_path_util.h | 75 ++++++++--------- source/blender/blenlib/BLI_string.h | 98 ++++++++++++----------- source/blender/blenlib/BLI_string_utils.h | 18 +++-- 3 files changed, 100 insertions(+), 91 deletions(-) diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h index 8f89fab0724..4c7901b6126 100644 --- a/source/blender/blenlib/BLI_path_util.h +++ b/source/blender/blenlib/BLI_path_util.h @@ -42,7 +42,7 @@ const char *BLI_getenv(const char *env) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT; * * \return true on success (i.e. given path now exists on file-system), false otherwise. */ -bool BLI_make_existing_file(const char *name); +bool BLI_make_existing_file(const char *name) ATTR_NONNULL(1); /** * Converts `/foo/bar.txt` to `/foo/` and `bar.txt` * @@ -58,35 +58,35 @@ void BLI_path_split_dir_file(const char *string, /** * Copies the parent directory part of string into `dir`, max length `dirlen`. */ -void BLI_path_split_dir_part(const char *string, char *dir, size_t dirlen); +void BLI_path_split_dir_part(const char *string, char *dir, size_t dirlen) ATTR_NONNULL(1, 2); /** * Copies the leaf filename part of string into `file`, max length `filelen`. */ -void BLI_path_split_file_part(const char *string, char *file, size_t filelen); +void BLI_path_split_file_part(const char *string, char *file, size_t filelen) ATTR_NONNULL(1, 2); /** * Returns a pointer to the last extension (e.g. the position of the last period). * Returns a pointer to the nil byte when no extension is found. */ const char *BLI_path_extension_or_end(const char *filepath) - ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL; + ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL; /** * Returns a pointer to the last extension (e.g. the position of the last period). * Returns NULL if there is no extension. */ -const char *BLI_path_extension(const char *filepath) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT; +const char *BLI_path_extension(const char *filepath) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT; /** * Append a filename to a dir, ensuring slash separates. * \return The new length of `dst`. */ size_t BLI_path_append(char *__restrict dst, size_t maxlen, const char *__restrict file) - ATTR_NONNULL(); + ATTR_NONNULL(1, 3); /** * A version of #BLI_path_append that ensures a trailing slash if there is space in `dst`. * \return The new length of `dst`. */ size_t BLI_path_append_dir(char *__restrict dst, size_t maxlen, const char *__restrict dir) - ATTR_NONNULL(); + ATTR_NONNULL(1, 3); /** * See #BLI_path_join doc-string. @@ -94,7 +94,7 @@ size_t BLI_path_append_dir(char *__restrict dst, size_t maxlen, const char *__re size_t BLI_path_join_array(char *__restrict dst, const size_t dst_len, const char *path_array[], - const int path_array_num); + const int path_array_num) ATTR_NONNULL(1, 3); /** * Join multiple strings into a path, ensuring only a single path separator between each, @@ -203,7 +203,7 @@ BLI_INLINE size_t _BLI_path_join_12(_BLI_PATH_JOIN_ARGS_10) * \return The pointer into \a path string immediately after last slash, * or start of \a path if none found. */ -const char *BLI_path_basename(const char *path) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT; +const char *BLI_path_basename(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT; /** * Get an element of the path at an index, eg: * `/some/path/file.txt` where an index of: @@ -219,20 +219,20 @@ const char *BLI_path_basename(const char *path) ATTR_NONNULL() ATTR_WARN_UNUSED_ bool BLI_path_name_at_index(const char *__restrict path, int index, int *__restrict r_offset, - int *__restrict r_len) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT; + int *__restrict r_len) ATTR_NONNULL(1, 3, 4) ATTR_WARN_UNUSED_RESULT; /** Return true only if #containee_path is contained in #container_path. */ -bool BLI_path_contains(const char *container_path, - const char *containee_path) ATTR_WARN_UNUSED_RESULT; +bool BLI_path_contains(const char *container_path, const char *containee_path) + ATTR_NONNULL(1, 2) ATTR_WARN_UNUSED_RESULT; /** * \return pointer to the leftmost path separator in string (or NULL when not found). */ -const char *BLI_path_slash_find(const char *string) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT; +const char *BLI_path_slash_find(const char *string) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT; /** * \return pointer to the rightmost path separator in string (or NULL when not found). */ -const char *BLI_path_slash_rfind(const char *string) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT; +const char *BLI_path_slash_rfind(const char *string) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT; /** * Appends a slash to string if there isn't one there already. * Returns the new length of the string. @@ -241,11 +241,11 @@ int BLI_path_slash_ensure(char *string, size_t string_maxlen) ATTR_NONNULL(1); /** * Removes the last slash and everything after it to the end of string, if there is one. */ -void BLI_path_slash_rstrip(char *string) ATTR_NONNULL(); +void BLI_path_slash_rstrip(char *string) ATTR_NONNULL(1); /** * Changes to the path separators to the native ones for this OS. */ -void BLI_path_slash_native(char *path) ATTR_NONNULL(); +void BLI_path_slash_native(char *path) ATTR_NONNULL(1); #ifdef _WIN32 bool BLI_path_program_extensions_add_win32(char *name, size_t maxlen); @@ -253,25 +253,25 @@ bool BLI_path_program_extensions_add_win32(char *name, size_t maxlen); /** * Search for a binary (executable) */ -bool BLI_path_program_search(char *fullname, size_t maxlen, const char *name); +bool BLI_path_program_search(char *fullname, size_t maxlen, const char *name) ATTR_NONNULL(1, 3); /** * \return true when `str` end with `ext` (case insensitive). */ bool BLI_path_extension_check(const char *str, const char *ext) - ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT; + ATTR_NONNULL(1, 2) ATTR_WARN_UNUSED_RESULT; bool BLI_path_extension_check_n(const char *str, ...) ATTR_NONNULL(1) ATTR_SENTINEL(0); /** * \return true when `str` ends with any of the suffixes in `ext_array`. */ bool BLI_path_extension_check_array(const char *str, const char **ext_array) - ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT; + ATTR_NONNULL(1, 2) ATTR_WARN_UNUSED_RESULT; /** * Semicolon separated wildcards, eg: `*.zip;*.py;*.exe` * does `str` match any of the semicolon-separated glob patterns in #fnmatch. */ bool BLI_path_extension_check_glob(const char *str, const char *ext_fnmatch) - ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT; + ATTR_NONNULL(1, 2) ATTR_WARN_UNUSED_RESULT; /** * Does basic validation of the given glob string, to prevent common issues from string * truncation. @@ -281,26 +281,27 @@ bool BLI_path_extension_check_glob(const char *str, const char *ext_fnmatch) * * \returns true if it had to modify given \a ext_fnmatch pattern. */ -bool BLI_path_extension_glob_validate(char *ext_fnmatch) ATTR_NONNULL(); +bool BLI_path_extension_glob_validate(char *ext_fnmatch) ATTR_NONNULL(1); /** * Removes any existing extension on the end of \a path and appends \a ext. * \return false if there was no room. */ -bool BLI_path_extension_replace(char *path, size_t maxlen, const char *ext) ATTR_NONNULL(); +bool BLI_path_extension_replace(char *path, size_t maxlen, const char *ext) ATTR_NONNULL(1, 3); /** * Remove the file extension. * \return true if a change was made to `path`. */ -bool BLI_path_extension_strip(char *path) ATTR_NONNULL(); +bool BLI_path_extension_strip(char *path) ATTR_NONNULL(1); /** * Strip's trailing '.'s and adds the extension only when needed */ -bool BLI_path_extension_ensure(char *path, size_t maxlen, const char *ext) ATTR_NONNULL(); +bool BLI_path_extension_ensure(char *path, size_t maxlen, const char *ext) ATTR_NONNULL(1, 3); /** * Ensure `filepath` has a file component, adding `filename` when it's empty or ends with a slash. * \return true if the `filename` was appended to `filepath`. */ -bool BLI_path_filename_ensure(char *filepath, size_t maxlen, const char *filename) ATTR_NONNULL(); +bool BLI_path_filename_ensure(char *filepath, size_t maxlen, const char *filename) + ATTR_NONNULL(1, 3); /** * Looks for a sequence of decimal digits in string, preceding any filename extension, * returning the integer value if found, or 0 if not. @@ -402,14 +403,14 @@ bool BLI_path_make_safe(char *path) ATTR_NONNULL(1); * * On success, the resulting path will always have a trailing slash. */ -bool BLI_path_parent_dir(char *path) ATTR_NONNULL(); +bool BLI_path_parent_dir(char *path) ATTR_NONNULL(1); /** * Go back until the directory is found. * * Strips off nonexistent (or non-accessible) sub-directories from the end of `dir`, * leaving the path of the lowest-level directory that does exist and we can read. */ -bool BLI_path_parent_dir_until_exists(char *path) ATTR_NONNULL(); +bool BLI_path_parent_dir_until_exists(char *path) ATTR_NONNULL(1); /** * If path begins with "//", strips that and replaces it with `basepath` directory. @@ -421,29 +422,29 @@ bool BLI_path_parent_dir_until_exists(char *path) ATTR_NONNULL(); * \param basepath: The directory to base relative paths with. * \return true if the path was relative (started with "//"). */ -bool BLI_path_abs(char *path, const char *basepath) ATTR_NONNULL(); +bool BLI_path_abs(char *path, const char *basepath) ATTR_NONNULL(1, 2); /** * Replaces "#" character sequence in last slash-separated component of `path` * with frame as decimal integer, with leading zeroes as necessary, to make digits. */ -bool BLI_path_frame(char *path, size_t path_maxncpy, int frame, int digits) ATTR_NONNULL(); +bool BLI_path_frame(char *path, size_t path_maxncpy, int frame, int digits) ATTR_NONNULL(1); /** * Replaces "#" character sequence in last slash-separated component of `path` * with sta and end as decimal integers, with leading zeroes as necessary, to make digits * digits each, with a hyphen in-between. */ -bool BLI_path_frame_range(char *path, int sta, int end, int digits) ATTR_NONNULL(); +bool BLI_path_frame_range(char *path, int sta, int end, int digits) ATTR_NONNULL(1); /** * Get the frame from a filename formatted by blender's frame scheme */ -bool BLI_path_frame_get(const char *path, int *r_frame, int *r_digits_len) ATTR_NONNULL(); +bool BLI_path_frame_get(const char *path, int *r_frame, int *r_digits_len) ATTR_NONNULL(1, 2, 3); /** * Given a `path` with digits representing frame numbers, replace the digits with the '#' * character and extract the extension. * So: `/some/path_123.jpeg` * Becomes: `/some/path_###` with `r_ext` set to `.jpeg`. */ -void BLI_path_frame_strip(char *path, char *r_ext, size_t ext_maxlen) ATTR_NONNULL(); +void BLI_path_frame_strip(char *path, char *r_ext, size_t ext_maxlen) ATTR_NONNULL(1, 2); /** * Check if we have '#' chars, usable for #BLI_path_frame, #BLI_path_frame_range */ @@ -462,18 +463,18 @@ bool BLI_path_is_abs_from_cwd(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED * This is _not_ something Blender's internal paths support, instead they use the "//" prefix. * In most cases #BLI_path_abs should be used instead. */ -bool BLI_path_abs_from_cwd(char *path, size_t maxlen) ATTR_NONNULL(); +bool BLI_path_abs_from_cwd(char *path, size_t maxlen) ATTR_NONNULL(1); /** * Replaces `file` with a relative version (prefixed by "//") such that #BLI_path_abs, given * the same `relfile`, will convert it back to its original value. */ -void BLI_path_rel(char *file, const char *relfile) ATTR_NONNULL(); +void BLI_path_rel(char *file, const char *relfile) ATTR_NONNULL(1); /** * Does path begin with the special "//" prefix that Blender uses to indicate * a path relative to the .blend file. */ -bool BLI_path_is_rel(const char *path) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT; +bool BLI_path_is_rel(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT; /** * Return true if the path is a UNC share. */ @@ -483,7 +484,7 @@ bool BLI_path_is_unc(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT; * Creates a display string from path to be used menus and the user interface. * Like `bpy.path.display_name()`. */ -void BLI_path_to_display_name(char *display_name, int maxlen, const char *name) ATTR_NONNULL(); +void BLI_path_to_display_name(char *display_name, int maxlen, const char *name) ATTR_NONNULL(1, 3); #if defined(WIN32) void BLI_path_normalize_unc_16(wchar_t *path_16); @@ -503,7 +504,7 @@ void BLI_path_normalize_unc(char *path_16, int maxlen); * \return true if succeeded */ bool BLI_path_suffix(char *string, size_t maxlen, const char *suffix, const char *sep) - ATTR_NONNULL(); + ATTR_NONNULL(1, 3, 4); /* Path string comparisons: case-insensitive for Windows, case-sensitive otherwise. */ #if defined(WIN32) diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h index 2daec88ffb6..0a329c0686b 100644 --- a/source/blender/blenlib/BLI_string.h +++ b/source/blender/blenlib/BLI_string.h @@ -41,7 +41,7 @@ extern "C" { * \param len: The number of bytes to duplicate * \retval Returns the duplicated string */ -char *BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +char *BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1); /** * Duplicates the cstring \a str into a newly mallocN'd @@ -50,7 +50,7 @@ char *BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESU * \param str: The string to be duplicated * \retval Returns the duplicated string */ -char *BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC; +char *BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC; /** * Appends the two strings, and returns new mallocN'ed string @@ -60,7 +60,7 @@ char *BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MA */ char *BLI_strdupcat(const char *__restrict str1, const char *__restrict str2) ATTR_WARN_UNUSED_RESULT - ATTR_NONNULL() ATTR_MALLOC; + ATTR_NONNULL(1, 2) ATTR_MALLOC; /** * Like strncpy but ensures dst is always @@ -72,7 +72,8 @@ char *BLI_strdupcat(const char *__restrict str1, * the size of dst) * \retval Returns dst */ -char *BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL(); +char *BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) + ATTR_NONNULL(1, 2); /** * Like BLI_strncpy but ensures dst is always padded by given char, @@ -87,7 +88,7 @@ char *BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxnc char *BLI_strncpy_ensure_pad(char *__restrict dst, const char *__restrict src, char pad, - size_t maxncpy) ATTR_NONNULL(); + size_t maxncpy) ATTR_NONNULL(1, 2); /** * Like strncpy but ensures dst is always @@ -104,10 +105,10 @@ char *BLI_strncpy_ensure_pad(char *__restrict dst, */ size_t BLI_strncpy_rlen(char *__restrict dst, const char *__restrict src, - size_t maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); + size_t maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2); size_t BLI_strcpy_rlen(char *__restrict dst, const char *__restrict src) ATTR_WARN_UNUSED_RESULT - ATTR_NONNULL(); + ATTR_NONNULL(1, 2); char *BLI_strncat(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL(1, 2); @@ -132,7 +133,7 @@ bool BLI_str_quoted_substr_range(const char *__restrict str, #if 0 /* UNUSED */ char *BLI_str_quoted_substrN(const char *__restrict str, const char *__restrict prefix) ATTR_WARN_UNUSED_RESULT - ATTR_NONNULL() ATTR_MALLOC; + ATTR_NONNULL(1, 2) ATTR_MALLOC; #endif /** * Fills \a result with text within "" that appear after some the contents of \a prefix. @@ -167,7 +168,7 @@ bool BLI_str_quoted_substr(const char *__restrict str, char *BLI_str_replaceN(const char *__restrict str, const char *__restrict substr_old, const char *__restrict substr_new) ATTR_WARN_UNUSED_RESULT - ATTR_NONNULL() ATTR_MALLOC; + ATTR_NONNULL(1, 2, 3) ATTR_MALLOC; /** * In-place replace every \a src to \a dst in \a str. @@ -176,7 +177,7 @@ char *BLI_str_replaceN(const char *__restrict str, * \param src: The character to replace. * \param dst: The character to replace with. */ -void BLI_str_replace_char(char *str, char src, char dst) ATTR_NONNULL(); +void BLI_str_replace_char(char *str, char src, char dst) ATTR_NONNULL(1); /** * Simple exact-match string replacement. @@ -244,7 +245,7 @@ int BLI_sprintf(char *__restrict str, const char *__restrict format, ...) ATTR_N * \note This is used for creating animation paths in blend files. */ size_t BLI_str_escape(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) - ATTR_NONNULL(); + ATTR_NONNULL(1, 2); /** * This roughly matches C and Python's string escaping with double quotes - `"`. * @@ -262,7 +263,7 @@ size_t BLI_str_unescape_ex(char *__restrict dst, size_t src_maxncpy, /* Additional arguments. */ size_t dst_maxncpy, - bool *r_is_complete) ATTR_NONNULL(); + bool *r_is_complete) ATTR_NONNULL(1, 2, 5); /** * See #BLI_str_unescape_ex doc-string. * @@ -274,7 +275,7 @@ size_t BLI_str_unescape_ex(char *__restrict dst, * \note This is used for parsing animation paths in blend files (runs often). */ size_t BLI_str_unescape(char *__restrict dst, const char *__restrict src, size_t src_maxncpy) - ATTR_NONNULL(); + ATTR_NONNULL(1, 2); /** * Find the first un-escaped quote in the string (to find the end of the string). @@ -284,7 +285,7 @@ size_t BLI_str_unescape(char *__restrict dst, const char *__restrict src, size_t * * \return The pointer to the first un-escaped quote. */ -const char *BLI_str_escape_find_quote(const char *str) ATTR_NONNULL(); +const char *BLI_str_escape_find_quote(const char *str) ATTR_NONNULL(1); /** * Format ints with decimal grouping. @@ -295,7 +296,7 @@ const char *BLI_str_escape_find_quote(const char *str) ATTR_NONNULL(); * \return The length of \a dst */ size_t BLI_str_format_int_grouped(char dst[BLI_STR_FORMAT_INT32_GROUPED_SIZE], int num) - ATTR_NONNULL(); + ATTR_NONNULL(1); /** * Format uint64_t with decimal grouping. * 1000 -> 1,000 @@ -305,7 +306,7 @@ size_t BLI_str_format_int_grouped(char dst[BLI_STR_FORMAT_INT32_GROUPED_SIZE], i * \return The length of \a dst */ size_t BLI_str_format_uint64_grouped(char dst[BLI_STR_FORMAT_UINT64_GROUPED_SIZE], uint64_t num) - ATTR_NONNULL(); + ATTR_NONNULL(1); /** * Format a size in bytes using binary units. * 1000 -> 1 KB @@ -318,7 +319,7 @@ size_t BLI_str_format_uint64_grouped(char dst[BLI_STR_FORMAT_UINT64_GROUPED_SIZE */ void BLI_str_format_byte_unit(char dst[BLI_STR_FORMAT_INT64_BYTE_UNIT_SIZE], long long int bytes, - bool base_10) ATTR_NONNULL(); + bool base_10) ATTR_NONNULL(1); /** * Format a count to up to 6 places (plus '\0' terminator) string using long number * names abbreviations. Used to produce a compact representation of large numbers. @@ -338,7 +339,7 @@ void BLI_str_format_byte_unit(char dst[BLI_STR_FORMAT_INT64_BYTE_UNIT_SIZE], * Length of 7 is the maximum of the resulting string, for example, `-15.5K\0`. */ void BLI_str_format_decimal_unit(char dst[BLI_STR_FORMAT_INT32_DECIMAL_UNIT_SIZE], - int number_to_format) ATTR_NONNULL(); + int number_to_format) ATTR_NONNULL(1); /** * Format a count to up to 3 places (plus minus sign, plus '\0' terminator) string using long * number names abbreviations. Used to produce a compact representation of large numbers as @@ -361,56 +362,57 @@ void BLI_str_format_decimal_unit(char dst[BLI_STR_FORMAT_INT32_DECIMAL_UNIT_SIZE * Length of 5 is the maximum of the resulting string, for example, `-15K\0`. */ void BLI_str_format_integer_unit(char dst[BLI_STR_FORMAT_INT32_INTEGER_UNIT_SIZE], - int number_to_format) ATTR_NONNULL(); + int number_to_format) ATTR_NONNULL(1); /** * Compare two strings without regard to case. * * \retval True if the strings are equal, false otherwise. */ -int BLI_strcaseeq(const char *a, const char *b) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +int BLI_strcaseeq(const char *a, const char *b) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2); /** * Portable replacement for `strcasestr` (not available in MSVC) */ -char *BLI_strcasestr(const char *s, const char *find) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +char *BLI_strcasestr(const char *s, const char *find) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2); /** * Variation of #BLI_strcasestr with string length limited to \a len */ char *BLI_strncasestr(const char *s, const char *find, size_t len) ATTR_WARN_UNUSED_RESULT - ATTR_NONNULL(); -int BLI_strcasecmp(const char *s1, const char *s2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); + ATTR_NONNULL(1, 2); +int BLI_strcasecmp(const char *s1, const char *s2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2); int BLI_strncasecmp(const char *s1, const char *s2, size_t len) ATTR_WARN_UNUSED_RESULT - ATTR_NONNULL(); + ATTR_NONNULL(1, 2); /** * Case insensitive, *natural* string comparison, * keeping numbers in order. */ -int BLI_strcasecmp_natural(const char *s1, const char *s2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +int BLI_strcasecmp_natural(const char *s1, const char *s2) ATTR_WARN_UNUSED_RESULT + ATTR_NONNULL(1, 2); /** - * Like strcmp, but will ignore any heading/trailing pad char for comparison. + * Like `strcmp`, but will ignore any heading/trailing pad char for comparison. * So e.g. if pad is '*', '*world' and 'world*' will compare equal. */ int BLI_strcmp_ignore_pad(const char *str1, const char *str2, char pad) ATTR_WARN_UNUSED_RESULT - ATTR_NONNULL(); + ATTR_NONNULL(1, 2); /** * Determine the length of a fixed-size string. */ -size_t BLI_strnlen(const char *str, size_t maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +size_t BLI_strnlen(const char *str, size_t maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1); /** * String case conversion, not affected by locale. */ -void BLI_str_tolower_ascii(char *str, size_t len) ATTR_NONNULL(); -void BLI_str_toupper_ascii(char *str, size_t len) ATTR_NONNULL(); +void BLI_str_tolower_ascii(char *str, size_t len) ATTR_NONNULL(1); +void BLI_str_toupper_ascii(char *str, size_t len) ATTR_NONNULL(1); -char BLI_tolower_ascii(const char c); -char BLI_toupper_ascii(const char c); +char BLI_tolower_ascii(const char c) ATTR_WARN_UNUSED_RESULT; +char BLI_toupper_ascii(const char c) ATTR_WARN_UNUSED_RESULT; /** * Strip white-space from end of the string. */ -void BLI_str_rstrip(char *str) ATTR_NONNULL(); +void BLI_str_rstrip(char *str) ATTR_NONNULL(1); /** * Strip trailing zeros from a float, eg: * 0.0000 -> 0.0 @@ -420,7 +422,7 @@ void BLI_str_rstrip(char *str) ATTR_NONNULL(); * \param pad: * \return The number of zeros stripped. */ -int BLI_str_rstrip_float_zero(char *str, char pad) ATTR_NONNULL(); +int BLI_str_rstrip_float_zero(char *str, char pad) ATTR_NONNULL(1); /** * Return index of a string in a string array. @@ -432,7 +434,7 @@ int BLI_str_rstrip_float_zero(char *str, char pad) ATTR_NONNULL(); */ int BLI_str_index_in_array_n(const char *__restrict str, const char **__restrict str_array, - int str_array_len) ATTR_NONNULL(); + int str_array_len) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1); /** * Return index of a string in a string array. * @@ -440,8 +442,9 @@ int BLI_str_index_in_array_n(const char *__restrict str, * \param str_array: Array of strings, (must be NULL-terminated). * \return The index of str in str_array or -1. */ -int BLI_str_index_in_array(const char *__restrict str, const char **__restrict str_array) - ATTR_NONNULL(); +int BLI_str_index_in_array(const char *__restrict str, + const char **__restrict str_array) ATTR_WARN_UNUSED_RESULT + ATTR_NONNULL(1, 2); /** * Find if a string starts with another string. @@ -450,7 +453,8 @@ int BLI_str_index_in_array(const char *__restrict str, const char **__restrict s * \param start: The string we look for at the start. * \return If str starts with start. */ -bool BLI_str_startswith(const char *__restrict str, const char *__restrict start) ATTR_NONNULL(); +bool BLI_str_startswith(const char *__restrict str, + const char *__restrict start) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2); /** * Find if a string ends with another string. * @@ -458,9 +462,9 @@ bool BLI_str_startswith(const char *__restrict str, const char *__restrict start * \param end: The string we look for at the end. * \return If str ends with end. */ -bool BLI_str_endswith(const char *__restrict str, const char *__restrict end) ATTR_NONNULL(); +bool BLI_str_endswith(const char *__restrict str, const char *__restrict end) ATTR_NONNULL(1, 2); bool BLI_strn_endswith(const char *__restrict str, const char *__restrict end, size_t length) - ATTR_NONNULL(); + ATTR_NONNULL(1, 2); /** * Find the first char matching one of the chars in \a delim, from left. @@ -473,7 +477,7 @@ bool BLI_strn_endswith(const char *__restrict str, const char *__restrict end, s * \return The length of the prefix (i.e. *sep - str). */ size_t BLI_str_partition(const char *str, const char delim[], const char **sep, const char **suf) - ATTR_NONNULL(); + ATTR_NONNULL(1, 2, 3, 4); /** * Find the first char matching one of the chars in \a delim, from right. * @@ -485,7 +489,7 @@ size_t BLI_str_partition(const char *str, const char delim[], const char **sep, * \return The length of the prefix (i.e. *sep - str). */ size_t BLI_str_rpartition(const char *str, const char delim[], const char **sep, const char **suf) - ATTR_NONNULL(); + ATTR_NONNULL(1, 2, 3, 4); /** * Find the first char matching one of the chars in \a delim, either from left or right. * @@ -505,12 +509,14 @@ size_t BLI_str_partition_ex(const char *str, const char **suf, bool from_right) ATTR_NONNULL(1, 3, 4, 5); -int BLI_string_max_possible_word_count(int str_len); -bool BLI_string_has_word_prefix(const char *haystack, const char *needle, size_t needle_len); +int BLI_string_max_possible_word_count(int str_len) ATTR_WARN_UNUSED_RESULT; +bool BLI_string_has_word_prefix(const char *haystack, + const char *needle, + size_t needle_len) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2); bool BLI_string_all_words_matched(const char *name, const char *str, int (*words)[2], - int words_len); + int words_len) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2, 3); /** * Find the ranges needed to split \a str into its individual words. @@ -526,7 +532,7 @@ int BLI_string_find_split_words(const char *str, size_t len, char delim, int r_words[][2], - int words_max) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); + int words_max) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 4); /* -------------------------------------------------------------------- */ /** \name String Copy/Format Macros diff --git a/source/blender/blenlib/BLI_string_utils.h b/source/blender/blenlib/BLI_string_utils.h index 8e157bb709b..8917f280228 100644 --- a/source/blender/blenlib/BLI_string_utils.h +++ b/source/blender/blenlib/BLI_string_utils.h @@ -34,18 +34,20 @@ typedef bool (*UniquenameCheckCallback)(void *arg, const char *name); * \param delim: Delimiter character`. * \return Length of \a left. */ -size_t BLI_split_name_num(char *left, int *nr, const char *name, char delim); -bool BLI_string_is_decimal(const char *string) ATTR_NONNULL(); +size_t BLI_split_name_num(char *left, int *nr, const char *name, char delim) ATTR_NONNULL(1, 2, 3); +bool BLI_string_is_decimal(const char *string) ATTR_NONNULL(1); /** * Based on `BLI_path_split_dir_file()` / `os.path.splitext()`, * `"a.b.c"` -> (`"a.b"`, `".c"`). */ -void BLI_string_split_suffix(const char *string, char *r_body, char *r_suf, size_t str_len); +void BLI_string_split_suffix(const char *string, char *r_body, char *r_suf, size_t str_len) + ATTR_NONNULL(1, 2, 3); /** * `"a.b.c"` -> (`"a."`, `"b.c"`). */ -void BLI_string_split_prefix(const char *string, char *r_pre, char *r_body, size_t str_len); +void BLI_string_split_prefix(const char *string, char *r_pre, char *r_body, size_t str_len) + ATTR_NONNULL(1, 2, 3); /** * A version of #BLI_string_join_array_by_sep_charN that takes a table array. @@ -54,7 +56,7 @@ void BLI_string_split_prefix(const char *string, char *r_pre, char *r_body, size char *BLI_string_join_array_by_sep_char_with_tableN(char sep, char *table[], const char *strings[], - uint strings_len) ATTR_NONNULL(); + uint strings_len) ATTR_NONNULL(2, 3); #define BLI_string_join_by_sep_char_with_tableN(sep, table, ...) \ BLI_string_join_array_by_sep_char_with_tableN( \ @@ -74,7 +76,7 @@ char *BLI_string_join_array_by_sep_char_with_tableN(char sep, size_t BLI_string_flip_side_name(char *r_name, const char *from_name, bool strip_number, - size_t name_len); + size_t name_len) ATTR_NONNULL(1, 2); /** * Ensures name is unique (according to criteria specified by caller in unique_check callback), @@ -93,7 +95,7 @@ bool BLI_uniquename_cb(UniquenameCheckCallback unique_check, const char *defname, char delim, char *name, - size_t name_len); + size_t name_len) ATTR_NONNULL(1, 3, 5); /** * Ensures that the specified block has a unique name within the containing list, * incrementing its numeric suffix as necessary. Returns true if name had to be adjusted. @@ -110,7 +112,7 @@ bool BLI_uniquename(struct ListBase *list, const char *defname, char delim, int name_offset, - size_t name_len); + size_t name_len) ATTR_NONNULL(1); /* Expand array functions. */