diff --git a/Makefile b/Makefile index 8ae4d095..385de893 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ QUIET?=@ -CFLAGS?=-Wall -Wextra -O3 +CFLAGS?=-Wall -Wextra -O3 -g VERSION?=0.14.1 PROGRAM=simpleswitcher diff --git a/source/dmenu-dialog.c b/source/dmenu-dialog.c index 32019a76..753e18c2 100644 --- a/source/dmenu-dialog.c +++ b/source/dmenu-dialog.c @@ -109,9 +109,6 @@ SwitcherMode dmenu_switcher_dialog ( char **input ) // act as a launcher char **list = get_dmenu( ); - if ( list == NULL ) { - return retv; - } int shift=0; int selected_line = 0; @@ -125,11 +122,11 @@ SwitcherMode dmenu_switcher_dialog ( char **input ) fputs( *input, stdout ); } - for ( unsigned int i=0; list[i] != NULL; i++ ) { + for ( unsigned int i=0; list != NULL && list[i] != NULL; i++ ) { free( list[i] ); } - free( list ); + if(list != NULL) free( list ); return retv; } diff --git a/source/simpleswitcher.c b/source/simpleswitcher.c index c7f8a03f..8f815c60 100644 --- a/source/simpleswitcher.c +++ b/source/simpleswitcher.c @@ -81,6 +81,7 @@ const char *cache_dir = NULL; void* allocate( unsigned long bytes ) { + if(bytes == 0) return NULL; void *ptr = malloc( bytes ); if ( !ptr ) { @@ -92,12 +93,14 @@ void* allocate( unsigned long bytes ) } void* allocate_clear( unsigned long bytes ) { + if(bytes == 0) return NULL; void *ptr = allocate( bytes ); memset( ptr, 0, bytes ); return ptr; } void* reallocate( void *ptr, unsigned long bytes ) { + if(bytes == 0) return NULL; ptr = realloc( ptr, bytes ); if ( !ptr ) { @@ -775,7 +778,7 @@ MenuReturn menu( char **lines, char **input, char *prompt, Time *time, int *shif int last_offset = 0; unsigned int selected = 0; - for ( ; lines[num_lines]; num_lines++ ); + for ( ; lines != NULL && lines[num_lines]; num_lines++ ); unsigned int max_lines = MIN( config.menu_lines, num_lines ); @@ -983,7 +986,7 @@ MenuReturn menu( char **lines, char **input, char *prompt, Time *time, int *shif if ( shift != NULL ) ( *shift ) = ( ( ev.xkey.state&ShiftMask ) == ShiftMask ); - if ( filtered[selected] ) { + if ( filtered && filtered[selected] ) { retv = MENU_OK; *selected_line = line_map[selected]; } else {