diff options
author | Colin Walters <walters@gnu.org> | 2002-04-05 09:18:57 +0000 |
---|---|---|
committer | Colin Walters <walters@gnu.org> | 2002-04-05 09:18:57 +0000 |
commit | f5bceaf89b3b88f42da85cbce98cadf9429c3974 (patch) | |
tree | 6881f631867fbfb7c2ba374886275d7451bb06b8 /lib-src/update-game-score.c | |
parent | cd553ffbf3c5eae5d6edb492ff62ce3fb6e7e6b8 (diff) | |
download | emacs-f5bceaf89b3b88f42da85cbce98cadf9429c3974.tar.gz |
Actually make previous changes work (oops).
Diffstat (limited to 'lib-src/update-game-score.c')
-rw-r--r-- | lib-src/update-game-score.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib-src/update-game-score.c b/lib-src/update-game-score.c index e713d732fef..084b54fdb32 100644 --- a/lib-src/update-game-score.c +++ b/lib-src/update-game-score.c @@ -189,6 +189,7 @@ read_score(FILE *f, struct score_entry *score) ; if (c == EOF) return -1; + ungetc(c, f); #ifdef HAVE_GETDELIM { int count = 0; @@ -200,7 +201,9 @@ read_score(FILE *f, struct score_entry *score) { int unameread = 0; int unamelen = 30; - char *username; + char *username = malloc(unamelen); + if (!username) + return -1; while ((c = getc(f)) != EOF && !isspace(c)) @@ -213,6 +216,9 @@ read_score(FILE *f, struct score_entry *score) username[unameread] = c; unameread++; } + if (c == EOF) + return -1; + username[unameread] = '\0'; score->username = username; } #endif @@ -231,7 +237,8 @@ read_score(FILE *f, struct score_entry *score) char *buf = malloc(len); if (!buf) return -1; - while ((c = getc(f)) != EOF) + while ((c = getc(f)) != EOF + && c != '\n') { if (cur >= len-1) { @@ -242,7 +249,6 @@ read_score(FILE *f, struct score_entry *score) cur++; } score->data = buf; - score->data[cur+1] = '\0'; } #endif /* Trim the newline */ |