mirror of
https://github.com/lbonn/rofi
synced 2024-11-15 08:37:17 +00:00
Make cppcheck happy. (normally we assume malloc does not fail.)
This commit is contained in:
parent
469b566614
commit
c400c44ec1
5 changed files with 57 additions and 32 deletions
|
@ -46,7 +46,12 @@ static char **get_dmenu ( void )
|
|||
|
||||
while ( fgets ( buffer, 1024, stdin ) != NULL )
|
||||
{
|
||||
retv = realloc ( retv, ( index + 2 ) * sizeof ( char* ) );
|
||||
char **tr = realloc ( retv, ( index + 2 ) * sizeof ( char* ) );
|
||||
if ( tr == NULL )
|
||||
{
|
||||
return retv;
|
||||
}
|
||||
retv = tr;
|
||||
retv[index] = strdup ( buffer );
|
||||
retv[index + 1] = NULL;
|
||||
|
||||
|
|
|
@ -94,7 +94,14 @@ static _element ** __history_get_element_list ( FILE *fd, unsigned int *length )
|
|||
{
|
||||
continue;
|
||||
}
|
||||
retv = realloc ( retv, ( *length + 2 ) * sizeof ( _element* ) );
|
||||
// Resize and check.
|
||||
_element **tr = realloc ( retv, ( *length + 2 ) * sizeof ( _element* ) );
|
||||
if ( tr == NULL )
|
||||
{
|
||||
return retv;
|
||||
}
|
||||
retv = tr;
|
||||
|
||||
retv[( *length )] = malloc ( sizeof ( _element ) );
|
||||
// remove trailing \n
|
||||
buffer[strlen ( buffer ) - 1] = '\0';
|
||||
|
@ -146,16 +153,23 @@ void history_set ( const char *filename, const char *entry )
|
|||
{
|
||||
// If not exists, add it.
|
||||
// Increase list by one
|
||||
list = realloc ( list, ( length + 2 ) * sizeof ( _element * ) );
|
||||
list[length] = malloc ( sizeof ( _element ) );
|
||||
// Copy name
|
||||
strncpy ( list[length]->name, entry, HISTORY_NAME_LENGTH );
|
||||
list[length]->name[HISTORY_NAME_LENGTH - 1] = '\0';
|
||||
// set # hits
|
||||
list[length]->index = 1;
|
||||
_element **tr = realloc ( list, ( length + 2 ) * sizeof ( _element* ) );
|
||||
if ( tr != NULL )
|
||||
{
|
||||
list = tr;
|
||||
list[length] = malloc ( sizeof ( _element ) );
|
||||
// Copy name
|
||||
if ( list[length] != NULL )
|
||||
{
|
||||
strncpy ( list[length]->name, entry, HISTORY_NAME_LENGTH );
|
||||
list[length]->name[HISTORY_NAME_LENGTH - 1] = '\0';
|
||||
// set # hits
|
||||
list[length]->index = 1;
|
||||
|
||||
length++;
|
||||
list[length] = NULL;
|
||||
length++;
|
||||
list[length] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Rewind.
|
||||
|
@ -173,15 +187,9 @@ void history_set ( const char *filename, const char *entry )
|
|||
// Free the list.
|
||||
for ( unsigned int iter = 0; iter < length; iter++ )
|
||||
{
|
||||
if ( list[iter] != NULL )
|
||||
{
|
||||
free ( list[iter] );
|
||||
}
|
||||
}
|
||||
if ( list != NULL )
|
||||
{
|
||||
free ( list );
|
||||
free ( list[iter] );
|
||||
}
|
||||
free ( list );
|
||||
// Close file.
|
||||
fclose ( fd );
|
||||
}
|
||||
|
|
|
@ -136,10 +136,14 @@ static char **tokenize ( const char *input )
|
|||
token != NULL;
|
||||
token = strtok_r ( NULL, " ", &saveptr ) )
|
||||
{
|
||||
retv = realloc ( retv, sizeof ( char* ) * ( num_tokens + 2 ) );
|
||||
retv[num_tokens + 1] = NULL;
|
||||
retv[num_tokens] = token;
|
||||
num_tokens++;
|
||||
char **tr = realloc ( retv, sizeof ( char* ) * ( num_tokens + 2 ) );
|
||||
if ( tr != NULL )
|
||||
{
|
||||
retv = tr;
|
||||
retv[num_tokens + 1] = NULL;
|
||||
retv[num_tokens] = token;
|
||||
num_tokens++;
|
||||
}
|
||||
}
|
||||
|
||||
return retv;
|
||||
|
@ -608,7 +612,7 @@ void monitor_dimensions ( Screen *screen, int x, int y, workarea *mon )
|
|||
mon->w = WidthOfScreen ( screen );
|
||||
mon->h = HeightOfScreen ( screen );
|
||||
|
||||
// locate the current monitor
|
||||
// locate the current monitor
|
||||
if ( XineramaIsActive ( display ) )
|
||||
{
|
||||
int monitors;
|
||||
|
|
|
@ -178,10 +178,14 @@ static char ** get_apps ( void )
|
|||
continue;
|
||||
}
|
||||
|
||||
retv = realloc ( retv, ( index + 2 ) * sizeof ( char* ) );
|
||||
retv[index] = strdup ( dent->d_name );
|
||||
retv[index + 1] = NULL;
|
||||
index++;
|
||||
char ** tr = realloc ( retv, ( index + 2 ) * sizeof ( char* ) );
|
||||
if ( tr != NULL )
|
||||
{
|
||||
retv = tr;
|
||||
retv[index] = strdup ( dent->d_name );
|
||||
retv[index + 1] = NULL;
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
closedir ( dir );
|
||||
|
|
|
@ -206,10 +206,14 @@ static char ** get_ssh ( void )
|
|||
continue;
|
||||
}
|
||||
|
||||
retv = realloc ( retv, ( index + 2 ) * sizeof ( char* ) );
|
||||
retv[index] = strndup ( &buffer[start], stop - start );
|
||||
retv[index + 1] = NULL;
|
||||
index++;
|
||||
char **tr = realloc ( retv, ( index + 2 ) * sizeof ( char* ) );
|
||||
if ( tr != NULL )
|
||||
{
|
||||
retv = tr;
|
||||
retv[index] = strndup ( &buffer[start], stop - start );
|
||||
retv[index + 1] = NULL;
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue