Now handles readline() returning NULL correctly (user hits CTRL-D, etc).
authorRyan C. Gordon <icculus@icculus.org>
Wed, 23 Oct 2002 00:29:25 +0000
changeset 500 6de777c231e3
parent 499 c362db7bb95f
child 501 fa1298d1157b
Now handles readline() returning NULL correctly (user hits CTRL-D, etc).
test/test_physfs.c
--- a/test/test_physfs.c	Wed Oct 23 00:28:56 2002 +0000
+++ b/test/test_physfs.c	Wed Oct 23 00:29:25 2002 +0000
@@ -714,10 +714,17 @@
 static int process_command(char *complete_cmd)
 {
     const command_info *i;
-    char *cmd_copy = malloc(strlen(complete_cmd) + 1);
+    char *cmd_copy;
     char *args;
     int rc = 1;
 
+    if (complete_cmd == NULL)  /* can happen if user hits CTRL-D, etc. */
+    {
+        printf("\n");
+        return(0);
+    } /* if */
+
+    cmd_copy = malloc(strlen(complete_cmd) + 1);
     if (cmd_copy == NULL)
     {
         printf("\n\n\nOUT OF MEMORY!\n\n\n");
@@ -877,7 +884,8 @@
 #endif
 
         rc = process_command(buf);
-        free(buf);
+        if (buf != NULL)
+            free(buf);
     } while (rc);
 
     if (!PHYSFS_deinit())