From: Max Kellermann Date: Sun, 21 Sep 2008 20:44:47 +0000 (+0200) Subject: support: added assertions X-Git-Tag: v0.12_alpha1~199 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=8beeb6e1d2311a3593a3df0273b778011068e81b;p=ncmpc.git support: added assertions Check the function parameters. --- diff --git a/src/support.c b/src/support.c index ad0f93b..6cf6113 100644 --- a/src/support.c +++ b/src/support.c @@ -21,6 +21,7 @@ #include "support.h" #include "ncmpc.h" +#include #include #include #include @@ -36,6 +37,8 @@ static gboolean noconvert = TRUE; size_t my_strlen(const char *str) { + assert(str != NULL); + if (g_utf8_validate(str, -1, NULL)) { size_t len = g_utf8_strlen(str, -1); size_t width = 0; @@ -91,6 +94,8 @@ basename(char *path) { char *end; + assert(path != NULL); + path = remove_trailing_slash(path); end = path + strlen(path); @@ -109,6 +114,9 @@ basename(char *path) char * strcasestr(const char *haystack, const char *needle) { + assert(haystack != NULL); + assert(needle != NULL); + return strstr(lowerstr(haystack), lowerstr(needle)); } #endif /* HAVE_STRCASESTR */ @@ -120,6 +128,10 @@ strscroll(char *str, char *separator, int width, scroll_state_t *st) gchar *tmp, *buf; gsize len, size; + assert(str != NULL); + assert(separator != NULL); + assert(st != NULL); + if( st->offset==0 ) { st->offset++; return g_strdup(str); @@ -170,6 +182,8 @@ utf8_to_locale(const char *utf8str) gsize rb, wb; GError *error; + assert(utf8str != NULL); + if (noconvert) return g_strdup(utf8str); @@ -201,6 +215,8 @@ locale_to_utf8(const char *localestr) gsize rb, wb; GError *error; + assert(localestr != NULL); + if (noconvert) return g_strdup(localestr);