From 3188236121cebe2300b20214a976c27b2dcba768 Mon Sep 17 00:00:00 2001 From: Qball Cow Date: Tue, 27 May 2014 08:42:21 +0200 Subject: [PATCH] Cleanups --- include/history.h | 9 ++++++--- source/history.c | 8 ++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/include/history.h b/include/history.h index 5a1c87ea..6ea75b8b 100644 --- a/include/history.h +++ b/include/history.h @@ -34,7 +34,8 @@ * 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. */ -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) * @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)); diff --git a/source/history.c b/source/history.c index 6c0f209b..4fabc5d9 100644 --- a/source/history.c +++ b/source/history.c @@ -248,10 +248,7 @@ void history_remove ( const char *filename, const char *entry ) // Free the list. for ( unsigned int iter = 0; iter < length; iter++ ) { - if ( list[iter] != NULL ) - { - free ( list[iter] ); - } + free ( list[iter] ); } if ( list != NULL ) { @@ -269,6 +266,8 @@ char ** history_get_list ( const char *filename, unsigned int *length ) FILE *fd = fopen ( filename, "r" ); if ( fd == NULL ) { + // File that does not exists is not an error, so ignore it. + // Everything else? panic. if ( errno != ENOENT ) { 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 ); // Copy list in right format. + // Lists are always short, so performance should not be an issue. if ( ( *length ) > 0 ) { retv = malloc ( ( ( *length ) + 1 ) * sizeof ( char * ) );