Skip to content

Commit

Permalink
Add RZ_NONNULL decoration for function arguments in str.c
Browse files Browse the repository at this point in the history
  • Loading branch information
DMaroo committed Feb 8, 2022
1 parent df2a153 commit 5035d58
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 36 deletions.
36 changes: 18 additions & 18 deletions librz/include/rz_util/rz_str.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ RZ_API char *rz_str_repeat(const char *ch, int sz);
RZ_API const char *rz_str_pad(const char ch, int len);
RZ_API const char *rz_str_rstr(const char *base, const char *p);
RZ_API const char *rz_strstr_ansi(const char *a, const char *b);
RZ_API const char *rz_str_rchr(const char *base, const char *p, int ch);
RZ_API const char *rz_str_rchr(RZ_NONNULL const char *base, const char *p, int ch);
RZ_API const char *rz_str_closer_chr(const char *b, const char *s);
RZ_API int rz_str_bounds(const char *str, int *h);
RZ_API char *rz_str_crop(const char *str, unsigned int x, unsigned int y, unsigned int x2, unsigned int y2);
Expand All @@ -79,26 +79,26 @@ RZ_API bool rz_str_range_in(const char *r, ut64 addr);
RZ_API size_t rz_str_len_utf8(const char *s);
RZ_API size_t rz_str_len_utf8_ansi(const char *str);
RZ_API size_t rz_str_len_utf8char(const char *s, int left);
RZ_API size_t rz_str_utf8_charsize(const char *str);
RZ_API size_t rz_str_utf8_charsize_prev(const char *str, int prev_len);
RZ_API size_t rz_str_utf8_charsize_last(const char *str);
RZ_API size_t rz_str_utf8_charsize(RZ_NONNULL const char *str);
RZ_API size_t rz_str_utf8_charsize_prev(RZ_NONNULL const char *str, int prev_len);
RZ_API size_t rz_str_utf8_charsize_last(RZ_NONNULL const char *str);
RZ_API void rz_str_filter_zeroline(char *str, int len);
RZ_API size_t rz_str_utf8_codepoint(const char *s, size_t left);
RZ_API bool rz_str_char_fullwidth(const char *s, size_t left);
RZ_API int rz_str_write(int fd, const char *b);
RZ_API size_t rz_str_ncpy(char *dst, const char *src, size_t n);
RZ_API size_t rz_str_ncpy(RZ_NONNULL char *dst, RZ_NONNULL const char *src, size_t n);
RZ_API void rz_str_sanitize(char *c);
RZ_API char *rz_str_sanitize_sdb_key(const char *s);
RZ_API const char *rz_str_casestr(const char *a, const char *b);
RZ_API const char *rz_str_firstbut(const char *s, char ch, const char *but);
RZ_API const char *rz_str_lastbut(const char *s, char ch, const char *but);
RZ_API size_t rz_str_split(char *str, char ch);
RZ_API RzList *rz_str_split_list(char *str, const char *c, int n);
RZ_API RzList *rz_str_split_duplist(const char *str, const char *c, bool trim);
RZ_API RzList *rz_str_split_duplist_n(const char *str, const char *c, int n, bool trim);
RZ_API size_t *rz_str_split_lines(char *str, size_t *count);
RZ_API size_t rz_str_split(RZ_NONNULL char *str, char ch);
RZ_API RzList *rz_str_split_list(RZ_NONNULL char *str, RZ_NONNULL const char *c, int n);
RZ_API RzList *rz_str_split_duplist(RZ_NONNULL const char *str, RZ_NONNULL const char *c, bool trim);
RZ_API RzList *rz_str_split_duplist_n(RZ_NONNULL const char *str, RZ_NONNULL const char *c, int n, bool trim);
RZ_API size_t *rz_str_split_lines(RZ_NONNULL char *str, size_t *count);
RZ_API char *rz_str_replace(char *str, const char *key, const char *val, int g);
RZ_API char *rz_str_replace_icase(char *str, const char *key, const char *val, int g, int keep_case);
RZ_API char *rz_str_replace_icase(RZ_NONNULL char *str, RZ_NONNULL const char *key, RZ_NONNULL const char *val, int g, int keep_case);
RZ_API char *rz_str_replace_in(char *str, ut32 sz, const char *key, const char *val, int g);
#define rz_str_cpy(x, y) memmove((x), (y), strlen(y) + 1);
#define rz_str_cat(x, y) memmove((x) + strlen(x), (y), strlen(y) + 1);
Expand All @@ -125,7 +125,7 @@ RZ_API bool rz_str_is_printable(const char *str);
RZ_API bool rz_str_is_printable_limited(const char *str, int size);
RZ_API bool rz_str_is_printable_incl_newlines(const char *str);
RZ_API char *rz_str_appendlen(char *ptr, const char *string, int slen);
RZ_API char *rz_str_newf(const char *fmt, ...) RZ_PRINTF_CHECK(1, 2);
RZ_API char *rz_str_newf(RZ_NONNULL const char *fmt, ...) RZ_PRINTF_CHECK(1, 2);
RZ_API char *rz_str_newlen(const char *str, int len);
RZ_API const char *rz_str_sysbits(const int v);
RZ_API char *rz_str_trunc_ellipsis(const char *str, int len);
Expand Down Expand Up @@ -164,7 +164,7 @@ RZ_API const char *rz_str_lchr(const char *str, char chr);
RZ_API const char *rz_sub_str_lchr(const char *str, int start, int end, char chr);
RZ_API const char *rz_sub_str_rchr(const char *str, int start, int end, char chr);
RZ_API char *rz_str_ichr(char *str, char chr);
RZ_API bool rz_str_ccmp(const char *dst, const char *orig, int ch);
RZ_API bool rz_str_ccmp(RZ_NONNULL const char *dst, RZ_NONNULL const char *orig, int ch);
RZ_API bool rz_str_cmp_list(const char *list, const char *item, char sep);
RZ_API int rz_str_cmp(const char *dst, const char *orig, int len);
RZ_API int rz_str_casecmp(const char *dst, const char *orig);
Expand All @@ -186,7 +186,7 @@ RZ_API wchar_t *rz_str_mb_to_wc(const char *buf);
RZ_API char *rz_str_wc_to_mb(const wchar_t *buf);
RZ_API wchar_t *rz_str_mb_to_wc_l(const char *buf, int len);
RZ_API char *rz_str_wc_to_mb_l(const wchar_t *buf, int len);
RZ_API const char *rz_str_str_xy(const char *s, const char *word, const char *prev, int *x, int *y);
RZ_API const char *rz_str_str_xy(RZ_NONNULL const char *s, RZ_NONNULL const char *word, const char *prev, RZ_NONNULL int *x, RZ_NONNULL int *y);

typedef void (*str_operation)(char *c);

Expand All @@ -199,7 +199,7 @@ RZ_API int rz_str_path_unescape(char *path);
RZ_API char *rz_str_path_escape(const char *path);
RZ_API int rz_str_unescape(char *buf);
RZ_API RZ_OWN char *rz_str_escape(RZ_NONNULL const char *buf);
RZ_API char *rz_str_escape_sh(const char *buf);
RZ_API char *rz_str_escape_sh(RZ_NONNULL const char *buf);
RZ_API char *rz_str_escape_dot(const char *buf);
RZ_API char *rz_str_escape_8bit(const char *buf, bool colors, RzStrEscOptions *opt);
RZ_API char *rz_str_escape_utf8(const char *buf, RzStrEscOptions *opt);
Expand All @@ -218,14 +218,14 @@ RZ_API char *rz_str_utf16_encode(const char *s, int len);
RZ_API char *rz_str_escape_utf8_for_json(const char *s, int len);
RZ_API char *rz_str_escape_mutf8_for_json(const char *s, int len);
RZ_API char *rz_str_home(const char *str);
RZ_API size_t rz_str_nlen(const char *s, size_t n);
RZ_API size_t rz_str_nlen(RZ_NONNULL const char *s, size_t n);
RZ_API size_t rz_str_nlen_w(const char *s, int n);
RZ_API size_t rz_wstr_clen(const char *s);
RZ_API char *rz_str_prepend(char *ptr, const char *string);
RZ_API char *rz_str_prefix_all(const char *s, const char *pfx);
RZ_API char *rz_str_append(char *ptr, const char *string);
RZ_API char *rz_str_append_owned(char *ptr, char *string);
RZ_API char *rz_str_appendf(char *ptr, const char *fmt, ...) RZ_PRINTF_CHECK(2, 3);
RZ_API char *rz_str_appendf(char *ptr, RZ_NONNULL const char *fmt, ...) RZ_PRINTF_CHECK(2, 3);
RZ_API char *rz_str_appendch(char *x, char y);
RZ_API void rz_str_case(char *str, bool up);
RZ_API void rz_str_trim_path(char *s);
Expand All @@ -248,7 +248,7 @@ RZ_API char *rz_str_from_ut64(ut64 val);
RZ_API void rz_str_stripLine(char *str, const char *key);
RZ_API char *rz_str_list_join(RzList *str, const char *sep);
RZ_API char *rz_str_array_join(const char **a, size_t n, const char *sep);
RZ_API RzList *rz_str_wrap(char *str, size_t width);
RZ_API RzList *rz_str_wrap(RZ_NONNULL char *str, size_t width);

RZ_API const char *rz_str_sep(const char *base, const char *sep);
RZ_API const char *rz_str_rsep(const char *base, const char *p, const char *sep);
Expand Down
36 changes: 18 additions & 18 deletions librz/util/str.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ RZ_API int rz_str_delta(char *p, char a, char b) {
* Replaces all instances of \p ch in \p str with a NULL byte and it returns
* the number of split strings.
*/
RZ_API size_t rz_str_split(char *str, char ch) {
RZ_API size_t rz_str_split(RZ_NONNULL char *str, char ch) {
rz_return_val_if_fail(str, 0);
size_t i;
char *p;
Expand Down Expand Up @@ -692,7 +692,7 @@ RZ_API const char *rz_str_rstr(const char *base, const char *p) {
return r;
}

RZ_API const char *rz_str_rchr(const char *base, const char *p, int ch) {
RZ_API const char *rz_str_rchr(RZ_NONNULL const char *base, const char *p, int ch) {
rz_return_val_if_fail(base, NULL);
if (!p) {
return strrchr(base, ch);
Expand Down Expand Up @@ -760,7 +760,7 @@ RZ_API char *rz_str_trunc_ellipsis(const char *str, int len) {
return buf;
}

RZ_API char *rz_str_newf(const char *fmt, ...) {
RZ_API char *rz_str_newf(RZ_NONNULL const char *fmt, ...) {
rz_return_val_if_fail(fmt, NULL);
va_list ap, ap2;

Expand All @@ -786,7 +786,7 @@ RZ_API char *rz_str_newf(const char *fmt, ...) {
*
* This API behaves like strlcpy or strscpy.
*/
RZ_API size_t rz_str_ncpy(char *dst, const char *src, size_t dst_size) {
RZ_API size_t rz_str_ncpy(RZ_NONNULL char *dst, RZ_NONNULL const char *src, size_t dst_size) {
rz_return_val_if_fail(dst && src, 0);

// do not do anything if dst_size is 0
Expand All @@ -804,7 +804,7 @@ RZ_API size_t rz_str_ncpy(char *dst, const char *src, size_t dst_size) {

/* memccmp("foo.bar", "foo.cow, '.') == 0 */
// Returns 1 if src and dst are equal up until the first instance of ch in src.
RZ_API bool rz_str_ccmp(const char *dst, const char *src, int ch) {
RZ_API bool rz_str_ccmp(RZ_NONNULL const char *dst, RZ_NONNULL const char *src, int ch) {
rz_return_val_if_fail(dst && src, false);
int i;
for (i = 0; src[i] && src[i] != ch; i++) {
Expand Down Expand Up @@ -938,7 +938,7 @@ RZ_API char *rz_str_append(char *ptr, const char *string) {
return ptr;
}

RZ_API char *rz_str_appendf(char *ptr, const char *fmt, ...) {
RZ_API char *rz_str_appendf(char *ptr, RZ_NONNULL const char *fmt, ...) {
rz_return_val_if_fail(fmt, NULL);
va_list ap, ap2;

Expand Down Expand Up @@ -1016,7 +1016,7 @@ RZ_API char *rz_str_replace(char *str, const char *key, const char *val, int g)
return str;
}

RZ_API char *rz_str_replace_icase(char *str, const char *key, const char *val, int g, int keep_case) {
RZ_API char *rz_str_replace_icase(RZ_NONNULL char *str, RZ_NONNULL const char *key, RZ_NONNULL const char *val, int g, int keep_case) {
rz_return_val_if_fail(str && key && val, NULL);

int off, i, klen, vlen, slen;
Expand Down Expand Up @@ -1416,7 +1416,7 @@ RZ_API RZ_OWN char *rz_str_escape(RZ_NONNULL const char *buf) {
}

// Return MUST BE surrounded by double-quotes
RZ_API char *rz_str_escape_sh(const char *buf) {
RZ_API char *rz_str_escape_sh(RZ_NONNULL const char *buf) {
rz_return_val_if_fail(buf, NULL);
char *new_buf = malloc(1 + strlen(buf) * 2);
if (!new_buf) {
Expand Down Expand Up @@ -1805,7 +1805,7 @@ RZ_API size_t rz_str_ansi_len(const char *str) {
return rz_str_ansi_nlen(str, 0);
}

RZ_API size_t rz_str_nlen(const char *str, size_t n) {
RZ_API size_t rz_str_nlen(RZ_NONNULL const char *str, size_t n) {
rz_return_val_if_fail(str, 0);
#if HAVE_STRNLEN
return strnlen(str, n);
Expand Down Expand Up @@ -2138,7 +2138,7 @@ RZ_API bool rz_str_char_fullwidth(const char *s, size_t left) {
* Returns 1 in case of ASCII
* str - Pointer to buffer
*/
RZ_API size_t rz_str_utf8_charsize(const char *str) {
RZ_API size_t rz_str_utf8_charsize(RZ_NONNULL const char *str) {
rz_return_val_if_fail(str, 0);
size_t size = 0;
size_t length = strlen(str);
Expand All @@ -2157,7 +2157,7 @@ RZ_API size_t rz_str_utf8_charsize(const char *str) {
* str - Pointer to leading utf8 char
* prev_len - Length in bytes of the buffer until str
*/
RZ_API size_t rz_str_utf8_charsize_prev(const char *str, int prev_len) {
RZ_API size_t rz_str_utf8_charsize_prev(RZ_NONNULL const char *str, int prev_len) {
rz_return_val_if_fail(str, 0);
int pos = 0;
size_t size = 0, minsize = RZ_MIN(5, prev_len);
Expand All @@ -2175,7 +2175,7 @@ RZ_API size_t rz_str_utf8_charsize_prev(const char *str, int prev_len) {
* Returns 1 in case of ASCII
* str - Pointer to buffer
*/
RZ_API size_t rz_str_utf8_charsize_last(const char *str) {
RZ_API size_t rz_str_utf8_charsize_last(RZ_NONNULL const char *str) {
rz_return_val_if_fail(str, 0);
size_t len = strlen(str);
return rz_str_utf8_charsize_prev(str + len, len);
Expand Down Expand Up @@ -3242,7 +3242,7 @@ static RzList *str_split_list_common(char *str, const char *c, int n, bool trim,
* \param c Delimiter string used to split \p str
* \param n If > 0 at most this number of delimiters are considered.
*/
RZ_API RzList *rz_str_split_list(char *str, const char *c, int n) {
RZ_API RzList *rz_str_split_list(RZ_NONNULL char *str, RZ_NONNULL const char *c, int n) {
rz_return_val_if_fail(str && c, NULL);
return str_split_list_common(str, c, n, true, false);
}
Expand All @@ -3258,7 +3258,7 @@ RZ_API RzList *rz_str_split_list(char *str, const char *c, int n) {
* \param c Delimiter string used to split \p str
* \param trim If true each token is considered without trailing/leading whitespaces.
*/
RZ_API RzList *rz_str_split_duplist(const char *_str, const char *c, bool trim) {
RZ_API RzList *rz_str_split_duplist(RZ_NONNULL const char *_str, RZ_NONNULL const char *c, bool trim) {
rz_return_val_if_fail(_str && c, NULL);
char *str = strdup(_str);
RzList *res = str_split_list_common(str, c, 0, trim, true);
Expand All @@ -3279,7 +3279,7 @@ RZ_API RzList *rz_str_split_duplist(const char *_str, const char *c, bool trim)
* \param n If > 0 at most this number of delimiters are considered.
* \param trim If true each token is considered without trailing/leading whitespaces.
*/
RZ_API RzList *rz_str_split_duplist_n(const char *_str, const char *c, int n, bool trim) {
RZ_API RzList *rz_str_split_duplist_n(RZ_NONNULL const char *_str, RZ_NONNULL const char *c, int n, bool trim) {
rz_return_val_if_fail(_str && c, NULL);
char *str = strdup(_str);
RzList *res = str_split_list_common(str, c, n, trim, true);
Expand All @@ -3297,7 +3297,7 @@ RZ_API RzList *rz_str_split_duplist_n(const char *_str, const char *c, int n, bo
* \param str Input string to split
* \param count Pointer to a size_t variable that can hold the number of lines.
*/
RZ_API size_t *rz_str_split_lines(char *str, size_t *count) {
RZ_API size_t *rz_str_split_lines(RZ_NONNULL char *str, size_t *count) {
rz_return_val_if_fail(str, NULL);
RzList *l = str_split_list_common(str, "\n", 0, false, false);
if (!l) {
Expand Down Expand Up @@ -3734,7 +3734,7 @@ RZ_API char *rz_str_scale(const char *s, int w, int h) {
return join;
}

RZ_API const char *rz_str_str_xy(const char *s, const char *word, const char *prev, int *x, int *y) {
RZ_API const char *rz_str_str_xy(RZ_NONNULL const char *s, RZ_NONNULL const char *word, const char *prev, RZ_NONNULL int *x, RZ_NONNULL int *y) {
rz_return_val_if_fail(s && word && x && y, NULL);
rz_return_val_if_fail(word[0] != '\0' && word[0] != '\n', NULL);
const char *src = prev ? prev + 1 : s;
Expand Down Expand Up @@ -3766,7 +3766,7 @@ RZ_API const char *rz_str_str_xy(const char *s, const char *word, const char *pr
* @param width the maximum size of each line. It will be respected only if
* possible, as the function won't split words.
*/
RZ_API RzList *rz_str_wrap(char *str, size_t width) {
RZ_API RzList *rz_str_wrap(RZ_NONNULL char *str, size_t width) {
rz_return_val_if_fail(str, NULL);

RzList *res = rz_list_new();
Expand Down

0 comments on commit 5035d58

Please sign in to comment.