This commit is contained in:
Qball Cow 2014-05-27 08:42:21 +02:00
parent 749d3e6223
commit 3188236121
2 changed files with 10 additions and 7 deletions

View File

@ -34,7 +34,8 @@
* Sets the entry in the history, if it exists its use-count is incremented. * Sets the entry in the history, if it exists its use-count is incremented.
* *
*/ */
void history_set ( const char *filename, const char *entry ); void history_set ( const char *filename, const char *entry )
__attribute__((nonnull));
/** /**
@ -43,7 +44,8 @@ void history_set ( const char *filename, const char *entry );
* *
* Removes the entry from the history. * Removes the entry from the history.
*/ */
void history_remove ( const char *filename, const char *entry ); void history_remove ( const char *filename, const char *entry )
__attribute__((nonnull));
/** /**
@ -53,7 +55,8 @@ void history_remove ( const char *filename, const char *entry );
* Gets the entries in the list (in order of usage) * Gets the entries in the list (in order of usage)
* @returns a list of entries length long. (and NULL terminated). * @returns a list of entries length long. (and NULL terminated).
*/ */
char ** history_get_list ( const char *filename, unsigned int * length ); char ** history_get_list ( const char *filename, unsigned int * length )
__attribute__((nonnull));

View File

@ -248,10 +248,7 @@ void history_remove ( const char *filename, const char *entry )
// Free the list. // Free the list.
for ( unsigned int iter = 0; iter < length; iter++ ) for ( unsigned int iter = 0; iter < length; iter++ )
{ {
if ( list[iter] != NULL ) free ( list[iter] );
{
free ( list[iter] );
}
} }
if ( list != NULL ) if ( list != NULL )
{ {
@ -269,6 +266,8 @@ char ** history_get_list ( const char *filename, unsigned int *length )
FILE *fd = fopen ( filename, "r" ); FILE *fd = fopen ( filename, "r" );
if ( fd == NULL ) if ( fd == NULL )
{ {
// File that does not exists is not an error, so ignore it.
// Everything else? panic.
if ( errno != ENOENT ) if ( errno != ENOENT )
{ {
fprintf ( stderr, "Failed to open file: %s\n", strerror ( errno ) ); fprintf ( stderr, "Failed to open file: %s\n", strerror ( errno ) );
@ -279,6 +278,7 @@ char ** history_get_list ( const char *filename, unsigned int *length )
list = __history_get_element_list ( fd, length ); list = __history_get_element_list ( fd, length );
// Copy list in right format. // Copy list in right format.
// Lists are always short, so performance should not be an issue.
if ( ( *length ) > 0 ) if ( ( *length ) > 0 )
{ {
retv = malloc ( ( ( *length ) + 1 ) * sizeof ( char * ) ); retv = malloc ( ( ( *length ) + 1 ) * sizeof ( char * ) );