changeset 44404:21e4d76a9e8a

Actually make previous changes work (oops).
author Colin Walters <walters@gnu.org>
date Fri, 05 Apr 2002 09:18:57 +0000
parents 0c1446851ed2
children 0ed69545b5f3
files lib-src/update-game-score.c
diffstat 1 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/lib-src/update-game-score.c	Fri Apr 05 08:58:12 2002 +0000
+++ b/lib-src/update-game-score.c	Fri Apr 05 09:18:57 2002 +0000
@@ -189,6 +189,7 @@
     ;
   if (c == EOF)
     return -1;
+  ungetc(c, f);
 #ifdef HAVE_GETDELIM
   {
     int count = 0;
@@ -200,7 +201,9 @@
   {
     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 @@
 	username[unameread] = c;
 	unameread++;
       }
+    if (c == EOF)    
+      return -1;
+    username[unameread] = '\0';
     score->username = username;
   }
 #endif
@@ -231,7 +237,8 @@
     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 @@
 	cur++;
       }
     score->data = buf;
-    score->data[cur+1] = '\0';
   }
 #endif
   /* Trim the newline */