summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorQball Cow <qball@gmpclient.org>2014-03-11 20:16:44 +0100
committerQball Cow <qball@gmpclient.org>2014-03-11 20:16:44 +0100
commitc268c10f8b8853249b4754738e5d5e36e5cf205a (patch)
tree61517ba91d6cd3909a79207b9d4bd56eba46e382 /source
parent5d706dc0dd3230a8d6d0d7af17634b3643de54ad (diff)
Fix warning from clang --analyze
Diffstat (limited to 'source')
-rw-r--r--source/run-dialog.c8
-rw-r--r--source/simpleswitcher.c17
-rw-r--r--source/ssh-dialog.c8
3 files changed, 23 insertions, 10 deletions
diff --git a/source/run-dialog.c b/source/run-dialog.c
index 9dab0c7e..2f76954d 100644
--- a/source/run-dialog.c
+++ b/source/run-dialog.c
@@ -221,7 +221,7 @@ static int sort_func ( const void *a, const void *b )
}
static char ** get_apps ( )
{
- int num_favorites = 0;
+ unsigned int num_favorites = 0;
unsigned int index = 0;
char *path;
char **retv = NULL;
@@ -277,7 +277,7 @@ static char ** get_apps ( )
// This is a nice little penalty, but doable? time will tell.
// given num_favorites is max 25.
- for ( int j = 0; found == 0 && j < num_favorites; j++ ) {
+ for ( unsigned int j = 0; found == 0 && j < num_favorites; j++ ) {
if ( strcasecmp( dent->d_name, retv[j] ) == 0 ) found = 1;
}
@@ -294,7 +294,9 @@ static char ** get_apps ( )
}
// TODO: check this is still fast enough. (takes 1ms on laptop.)
- qsort( &retv[num_favorites],index-num_favorites, sizeof( char* ), sort_func );
+ if(index > num_favorites) {
+ qsort( &retv[num_favorites],index-num_favorites, sizeof( char* ), sort_func );
+ }
free( path );
#ifdef TIMING
clock_gettime( CLOCK_REALTIME, &stop );
diff --git a/source/simpleswitcher.c b/source/simpleswitcher.c
index 4dc390fd..ca80769a 100644
--- a/source/simpleswitcher.c
+++ b/source/simpleswitcher.c
@@ -340,12 +340,15 @@ winlist* winlist_new()
l->data = allocate( sizeof( void* ) * ( WINLIST+1 ) );
return l;
}
-int winlist_append( winlist *l, Window w, void *d )
+int winlist_append( winlist *l , Window w, void *d )
{
if ( l->len > 0 && !( l->len % WINLIST ) ) {
l->array = reallocate( l->array, sizeof( Window ) * ( l->len+WINLIST+1 ) );
l->data = reallocate( l->data, sizeof( void* ) * ( l->len+WINLIST+1 ) );
}
+ // Make clang-check happy.
+ // TODO: make clang-check clear this should never be 0.
+ if(l->data == NULL || l->array == NULL) return 0;
l->data[l->len] = d;
l->array[l->len++] = w;
@@ -503,10 +506,16 @@ char* window_get_text_prop( Window w, Atom atom )
if ( XGetTextProperty( display, w, &prop, atom ) && prop.value && prop.nitems ) {
if ( prop.encoding == XA_STRING ) {
res = allocate( strlen( ( char* )prop.value )+1 );
- strcpy( res, ( char* )prop.value );
+ // make clang-check happy.
+ if(res) {
+ strcpy( res, ( char* )prop.value );
+ }
} else if ( Xutf8TextPropertyToTextList( display, &prop, &list, &count ) >= Success && count > 0 && *list ) {
res = allocate( strlen( *list )+1 );
- strcpy( res, *list );
+ // make clang-check happy.
+ if(res) {
+ strcpy( res, *list );
+ }
XFreeStringList( list );
}
}
@@ -732,7 +741,7 @@ static int calculate_common_prefix( char **filtered, int max_lines )
{
int length_prefix = 0;
- if ( filtered[0] != NULL ) {
+ if ( filtered && filtered[0] != NULL ) {
int found = 1;
char *p = filtered[0];
diff --git a/source/ssh-dialog.c b/source/ssh-dialog.c
index 87f86bb9..bc1af0a8 100644
--- a/source/ssh-dialog.c
+++ b/source/ssh-dialog.c
@@ -193,7 +193,7 @@ static int sort_func ( const void *a, const void *b )
}
static char ** get_ssh ( )
{
- int num_favorites = 0;
+ unsigned int num_favorites = 0;
unsigned int index = 0;
char *path;
char **retv = NULL;
@@ -246,7 +246,7 @@ static char ** get_ssh ( )
// This is a nice little penalty, but doable? time will tell.
// given num_favorites is max 25.
- for ( int j = 0; found == 0 && j < num_favorites; j++ ) {
+ for ( unsigned int j = 0; found == 0 && j < num_favorites; j++ ) {
if ( strncasecmp( &buffer[start], retv[j],stop-start ) == 0 ) found = 1;
}
@@ -263,7 +263,9 @@ static char ** get_ssh ( )
}
// TODO: check this is still fast enough. (takes 1ms on laptop.)
- qsort( &retv[num_favorites],index-num_favorites, sizeof( char* ), sort_func );
+ if(index > num_favorites) {
+ qsort( &retv[num_favorites],index-num_favorites, sizeof( char* ), sort_func );
+ }
free( path );
#ifdef TIMING
clock_gettime( CLOCK_REALTIME, &stop );