From b91bc4f037b5c3ce69fef2d6187690ce05ffea62 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 8 Jul 2012 06:00:27 +0000 Subject: use gcc attrubutes to warn on unused return values and arguments which shouldnt be NULL. also remove IDP_AppendArray's return value which wasnt the new item in the array (which is odd/misleading), but wasnt used anywhere either. --- source/blender/blenlib/BLI_string.h | 113 ++++++++++++++++++++++++++++++------ 1 file changed, 96 insertions(+), 17 deletions(-) (limited to 'source/blender/blenlib/BLI_string.h') diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h index c8f439c677f..8fde8fcf13f 100644 --- a/source/blender/blenlib/BLI_string.h +++ b/source/blender/blenlib/BLI_string.h @@ -43,7 +43,12 @@ extern "C" { * \param str The string to be duplicated * \retval Returns the duplicated string */ -char *BLI_strdup(const char *str); +char *BLI_strdup(const char *str) +#ifdef __GNUC__ +__attribute__((warn_unused_result)) +__attribute__((nonnull)) +#endif +; /** * Duplicates the first \a len bytes of cstring \a str @@ -54,7 +59,12 @@ char *BLI_strdup(const char *str); * \param len The number of bytes to duplicate * \retval Returns the duplicated string */ -char *BLI_strdupn(const char *str, const size_t len); +char *BLI_strdupn(const char *str, const size_t len) +#ifdef __GNUC__ +__attribute__((warn_unused_result)) +__attribute__((nonnull)) +#endif +; /** * Appends the two strings, and returns new mallocN'ed string @@ -62,7 +72,12 @@ char *BLI_strdupn(const char *str, const size_t len); * \param str2 second string for append * \retval Returns dst */ -char *BLI_strdupcat(const char *str1, const char *str2); +char *BLI_strdupcat(const char *str1, const char *str2) +#ifdef __GNUC__ +__attribute__((warn_unused_result)) +__attribute__((nonnull)) +#endif +; /** * Like strncpy but ensures dst is always @@ -74,9 +89,14 @@ char *BLI_strdupcat(const char *str1, const char *str2); * the size of dst) * \retval Returns dst */ -char *BLI_strncpy(char *dst, const char *src, const size_t maxncpy); +char *BLI_strncpy(char *dst, const char *src, const size_t maxncpy) +#ifdef __GNUC__ +__attribute__((nonnull)) +#endif +; -/* Makes a copy of the text within the "" that appear after some text 'blahblah' +/** + *Makes a copy of the text within the "" that appear after some text 'blahblah' * i.e. for string 'pose["apples"]' with prefix 'pose[', it should grab "apples" * * - str: is the entire string to chop @@ -85,7 +105,12 @@ char *BLI_strncpy(char *dst, const char *src, const size_t maxncpy); * Assume that the strings returned must be freed afterwards, and that the inputs will contain * data we want... */ -char *BLI_getQuotedStr(const char *str, const char *prefix); +char *BLI_getQuotedStr(const char *str, const char *prefix) +#ifdef __GNUC__ +__attribute__((warn_unused_result)) +__attribute__((nonnull)) +#endif +; /** * Returns a copy of the cstring \a str into a newly mallocN'd @@ -97,7 +122,12 @@ char *BLI_getQuotedStr(const char *str, const char *prefix); * \param newText The text in the string to find and replace * \retval Returns the duplicated string */ -char *BLI_replacestr(char *str, const char *oldText, const char *newText); +char *BLI_replacestr(char *str, const char *oldText, const char *newText) +#ifdef __GNUC__ +__attribute__((warn_unused_result)) +__attribute__((nonnull)) +#endif +; /* * Replacement for snprintf @@ -105,6 +135,7 @@ char *BLI_replacestr(char *str, const char *oldText, const char *newText); size_t BLI_snprintf(char *buffer, size_t len, const char *format, ...) #ifdef __GNUC__ __attribute__ ((format(printf, 3, 4))) +__attribute__((nonnull)) #endif ; @@ -115,27 +146,75 @@ __attribute__ ((format(printf, 3, 4))) char *BLI_sprintfN(const char *format, ...) #ifdef __GNUC__ __attribute__ ((format(printf, 1, 2))) +__attribute__((warn_unused_result)) +__attribute__((nonnull)) #endif ; -size_t BLI_strescape(char *dst, const char *src, const size_t maxlen); +size_t BLI_strescape(char *dst, const char *src, const size_t maxlen) +#ifdef __GNUC__ +__attribute__((nonnull)) +#endif +; /** * 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); +int BLI_strcaseeq(const char *a, const char *b) +#ifdef __GNUC__ +__attribute__((warn_unused_result)) +__attribute__((nonnull)) +#endif +; -char *BLI_strcasestr(const char *s, const char *find); -int BLI_strcasecmp(const char *s1, const char *s2); -int BLI_strncasecmp(const char *s1, const char *s2, size_t len); -int BLI_natstrcmp(const char *s1, const char *s2); -size_t BLI_strnlen(const char *str, size_t maxlen); -void BLI_timestr(double _time, char *str); /* time var is global */ +char *BLI_strcasestr(const char *s, const char *find) +#ifdef __GNUC__ +__attribute__((warn_unused_result)) +__attribute__((nonnull)) +#endif +; +int BLI_strcasecmp(const char *s1, const char *s2) +#ifdef __GNUC__ +__attribute__((warn_unused_result)) +__attribute__((nonnull)) +#endif +; +int BLI_strncasecmp(const char *s1, const char *s2, size_t len) +#ifdef __GNUC__ +__attribute__((warn_unused_result)) +__attribute__((nonnull)) +#endif +; +int BLI_natstrcmp(const char *s1, const char *s2) +#ifdef __GNUC__ +__attribute__((warn_unused_result)) +__attribute__((nonnull)) +#endif +; +size_t BLI_strnlen(const char *str, size_t maxlen) +#ifdef __GNUC__ +__attribute__((warn_unused_result)) +__attribute__((nonnull)) +#endif +; +void BLI_timestr(double _time, char *str) +#ifdef __GNUC__ +__attribute__((nonnull)) +#endif +; /* time var is global */ -void BLI_ascii_strtolower(char *str, int len); -void BLI_ascii_strtoupper(char *str, int len); +void BLI_ascii_strtolower(char *str, int len) +#ifdef __GNUC__ +__attribute__((nonnull)) +#endif +; +void BLI_ascii_strtoupper(char *str, int len) +#ifdef __GNUC__ +__attribute__((nonnull)) +#endif +; #ifdef __cplusplus } -- cgit v1.2.3