diff options
author | James Booth <boothj5@gmail.com> | 2012-10-14 04:13:00 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2012-10-14 04:13:00 +0100 |
commit | 993554b1b09a9397ddc5510507179f77f3341160 (patch) | |
tree | 23366b4573ce5b0850edb9c7e5e0e392581d6ada /src | |
parent | 579201636ed255bddee6564f41511819479eff9e (diff) | |
download | profani-tty-993554b1b09a9397ddc5510507179f77f3341160.tar.gz |
Fixed history when no log
Diffstat (limited to 'src')
-rw-r--r-- | src/chat_log.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/chat_log.c b/src/chat_log.c index 5d8df0da..b67b5988 100644 --- a/src/chat_log.c +++ b/src/chat_log.c @@ -101,16 +101,18 @@ chat_log_get_previous(const gchar * const login, gchar *recipient, FILE *logp = fopen(filename, "r"); char *line = NULL; size_t read = 0; - size_t length = getline(&line, &read, logp); - while (length != -1) { - char *copy = malloc(length); - copy = strncpy(copy, line, length); - copy[length -1] = '\0'; - history = g_slist_append(history, copy); - free(line); - line = NULL; - read = 0; - length = getline(&line, &read, logp); + if (logp != NULL) { + size_t length = getline(&line, &read, logp); + while (length != -1) { + char *copy = malloc(length); + copy = strncpy(copy, line, length); + copy[length -1] = '\0'; + history = g_slist_append(history, copy); + free(line); + line = NULL; + read = 0; + length = getline(&line, &read, logp); + } } free(filename); |