OSDN Git Service

Don't write into line[-1] when line starts with a NUL byte.
authorJim Meyering <meyering@redhat.com>
Mon, 4 Feb 2008 07:35:17 +0000 (08:35 +0100)
committerJim Meyering <meyering@redhat.com>
Mon, 4 Feb 2008 07:35:17 +0000 (08:35 +0100)
* parted/ui.c (_readline): Check strlen first.

parted/ui.c

index 370c2be..d9ab107 100644 (file)
@@ -572,7 +572,9 @@ _readline (const char* prompt, const StrList* possibilities)
                         fputs (line, stdout);
                         fflush (stdout);
 #endif
-                        line [strlen (line) - 1] = 0;    /* kill trailing CR */
+                        /* kill trailing NL */
+                        if (strlen (line))
+                                line [strlen (line) - 1] = 0;
                 } else {
                         free (line);
                         line = NULL;