1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

Small 'correctness' fixes (thx to sparse)

This commit is contained in:
QC 2014-05-17 23:06:45 +02:00
parent f44fd74987
commit 4f1ab47b7d
5 changed files with 17 additions and 13 deletions

View file

@ -33,12 +33,12 @@
#include <strings.h> #include <strings.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include "rofi.h" #include "rofi.h"
#include "dmenu-dialog.h"
char *dmenu_prompt = "dmenu "; char *dmenu_prompt = "dmenu ";
static char **get_dmenu ( ) static char **get_dmenu ( void )
{ {
char buffer[1024]; char buffer[1024];
char **retv = NULL; char **retv = NULL;

View file

@ -69,6 +69,7 @@ static void __history_write_element_list( FILE *fd, _element **list, unsigned in
static _element ** __history_get_element_list ( FILE *fd, unsigned int *length ) static _element ** __history_get_element_list ( FILE *fd, unsigned int *length )
{ {
char buffer[HISTORY_NAME_LENGTH+16];
_element **retv = NULL; _element **retv = NULL;
if (length == NULL) if (length == NULL)
@ -81,9 +82,9 @@ static _element ** __history_get_element_list ( FILE *fd, unsigned int *length )
{ {
return NULL; return NULL;
} }
char buffer[HISTORY_NAME_LENGTH+16];
while ( fgets (buffer, HISTORY_NAME_LENGTH+16, fd ) != NULL) while ( fgets (buffer, HISTORY_NAME_LENGTH+16, fd ) != NULL)
{ {
char * start = NULL;
// Skip empty lines. // Skip empty lines.
if ( strlen ( buffer ) == 0 ) if ( strlen ( buffer ) == 0 )
{ {
@ -94,7 +95,6 @@ static _element ** __history_get_element_list ( FILE *fd, unsigned int *length )
// remove trailing \n // remove trailing \n
buffer[strlen ( buffer ) - 1] = '\0'; buffer[strlen ( buffer ) - 1] = '\0';
// Parse the number of times. // Parse the number of times.
char * start = NULL;
retv[(*length)]->index = strtol ( buffer, &start, 10 ); retv[(*length)]->index = strtol ( buffer, &start, 10 );
strncpy(retv[(*length)]->name, (start+1),HISTORY_NAME_LENGTH); strncpy(retv[(*length)]->name, (start+1),HISTORY_NAME_LENGTH);
// Force trailing '\0' // Force trailing '\0'
@ -112,6 +112,7 @@ void history_set ( const char *filename, const char *entry )
int found = 0; int found = 0;
unsigned int curr = 0; unsigned int curr = 0;
unsigned int length = 0; unsigned int length = 0;
_element **list = NULL;
// Open file for reading and writing. // Open file for reading and writing.
FILE *fd = fopen(filename, "a+"); FILE *fd = fopen(filename, "a+");
if(fd == NULL) if(fd == NULL)
@ -120,7 +121,7 @@ void history_set ( const char *filename, const char *entry )
return ; return ;
} }
// Get list. // Get list.
_element ** list = __history_get_element_list(fd, &length); list = __history_get_element_list(fd, &length);
// Look if the entry exists. // Look if the entry exists.
for(unsigned int iter = 0;!found && iter < length; iter++) for(unsigned int iter = 0;!found && iter < length; iter++)
@ -172,6 +173,7 @@ void history_set ( const char *filename, const char *entry )
void history_remove ( const char *filename, const char *entry ) void history_remove ( const char *filename, const char *entry )
{ {
_element ** list = NULL;
int found = 0; int found = 0;
unsigned int curr = 0; unsigned int curr = 0;
unsigned int length = 0; unsigned int length = 0;
@ -183,7 +185,7 @@ void history_remove ( const char *filename, const char *entry )
return ; return ;
} }
// Get list. // Get list.
_element ** list = __history_get_element_list(fd, &length); list = __history_get_element_list(fd, &length);
// Find entry. // Find entry.
for(unsigned int iter = 0;!found && iter < length; iter++) for(unsigned int iter = 0;!found && iter < length; iter++)
@ -228,7 +230,8 @@ void history_remove ( const char *filename, const char *entry )
char ** history_get_list ( const char *filename, unsigned int *length ) char ** history_get_list ( const char *filename, unsigned int *length )
{ {
char **retv = NULL; _element **list = NULL;
char **retv = NULL;
// Open file. // Open file.
FILE *fd = fopen(filename, "r"); FILE *fd = fopen(filename, "r");
if(fd == NULL) if(fd == NULL)
@ -239,7 +242,7 @@ char ** history_get_list ( const char *filename, unsigned int *length )
return NULL; return NULL;
} }
// Get list. // Get list.
_element ** list = __history_get_element_list(fd, length); list = __history_get_element_list(fd, length);
// Copy list in right format. // Copy list in right format.
if((*length) > 0 ) if((*length) > 0 )

View file

@ -112,7 +112,7 @@ static int sort_func ( const void *a, const void *b )
const char *bstr = *( const char * const * ) b; const char *bstr = *( const char * const * ) b;
return strcasecmp ( astr, bstr ); return strcasecmp ( astr, bstr );
} }
static char ** get_apps ( ) static char ** get_apps ( void )
{ {
unsigned int num_favorites = 0; unsigned int num_favorites = 0;
unsigned int index = 0; unsigned int index = 0;

View file

@ -71,7 +71,7 @@ static inline int execshssh ( const char *host )
int retv = execvp ( config.terminal_emulator, (char * const *)args ); int retv = execvp ( config.terminal_emulator, (char * const *)args );
// Free the args list. // Free the args list.
for(int i =0; i < 7;i++) { for(i =0; i < 7;i++) {
if(args[i] != NULL) { if(args[i] != NULL) {
free(args[i]); free(args[i]);
} }
@ -128,7 +128,7 @@ static int sort_func ( const void *a, const void *b )
const char *bstr = *( const char * const * ) b; const char *bstr = *( const char * const * ) b;
return strcasecmp ( astr, bstr ); return strcasecmp ( astr, bstr );
} }
static char ** get_ssh ( ) static char ** get_ssh ( void )
{ {
unsigned int num_favorites = 0; unsigned int num_favorites = 0;
unsigned int index = 0; unsigned int index = 0;

View file

@ -50,7 +50,7 @@ typedef struct
char ** str; char ** str;
}; };
} XrmOption; } XrmOption;
XrmOption xrmOptions[] = { static XrmOption xrmOptions[] = {
{ xrm_Number, "opacity", { .num = &config.window_opacity } }, { xrm_Number, "opacity", { .num = &config.window_opacity } },
{ xrm_Number, "width", { .num = &config.menu_width } }, { xrm_Number, "width", { .num = &config.menu_width } },
{ xrm_Number, "lines", { .num = &config.menu_lines } }, { xrm_Number, "lines", { .num = &config.menu_lines } },
@ -72,9 +72,10 @@ XrmOption xrmOptions[] = {
void parse_xresource_options ( Display *display ) void parse_xresource_options ( Display *display )
{ {
char *xRMS;
// Map Xresource entries to simpleswitcher config options. // Map Xresource entries to simpleswitcher config options.
XrmInitialize (); XrmInitialize ();
char * xRMS = XResourceManagerString ( display ); xRMS = XResourceManagerString ( display );
if ( xRMS != NULL ) if ( xRMS != NULL )
{ {