bug-inetutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-inetutils] [PATCH] Do not segfault on lines without a new line char


From: Guillem Jover
Subject: [bug-inetutils] [PATCH] Do not segfault on lines without a new line character
Date: Sun, 6 Dec 2009 04:55:19 +0100
User-agent: Mutt/1.5.20 (2009-06-14)

        * hostname/hostname.c (parse_file): Remove initial getline.
        Change `while { }' to `do { } while'.  Move getline in the
        loop to the beginning.
---
 hostname/hostname.c |   15 ++++++---------
 1 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/hostname/hostname.c b/hostname/hostname.c
index c00e0f7..af8cf77 100644
--- a/hostname/hostname.c
+++ b/hostname/hostname.c
@@ -377,23 +377,20 @@ parse_file (const char *const file_name)
   if (file == NULL)
     error (EXIT_FAILURE, errno, "fopen");
 
-  nread = getline (&buffer, &size, file);
-  if (nread == -1)
-    error (EXIT_FAILURE, errno, "getline");
-
-  while (feof (file) == 0)
+  do
     {
+      nread = getline (&buffer, &size, file);
+      if (nread == -1)
+        error (EXIT_FAILURE, errno, "getline");
+
       if (buffer[0] != '#')
         {
           name = xmalloc (sizeof (char) * nread);
           sscanf (buffer, "%s", name);
           break;
         }
-
-      nread = getline (&buffer, &size, file);
-      if (nread == -1)
-        error (EXIT_FAILURE, errno, "getline");
     }
+  while (feof (file) == 0);
 
   free (buffer);
   fclose (file);
-- 
1.6.5.4





reply via email to

[Prev in Thread] Current Thread [Next in Thread]