line-reader: Fix null derefe in line_reader_for_fd() with null encoding.
authorBen Pfaff <blp@cs.stanford.edu>
Fri, 4 Apr 2014 05:12:49 +0000 (22:12 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Fri, 4 Apr 2014 05:12:49 +0000 (22:12 -0700)
This function is supposed to treat NULL and "Auto" the same way, but it
tried to xstrdup NULL, which doesn't work.

This is easy to reproduce by attempting to use File|Import Data to read
a short file whose contents are all ASCII.

Bug #41971.
Reported by Mindaugus.

src/libpspp/line-reader.c

index 56a368da2965f08f6c7d9c43aa69ae5cfca155d9..cb4bd014b93ef6b90bd4e75d8649a216be009e2b 100644 (file)
@@ -125,7 +125,7 @@ line_reader_for_fd (const char *encoding, int fd)
       && !strcmp (r->encoding, "ASCII"))
     {
       r->state = S_AUTO;
-      r->auto_encoding = xstrdup (encoding);
+      r->auto_encoding = encoding ? xstrdup (encoding) : NULL;
     }
   else
     r->state = r->encoding_info.unit == 1 ? S_UNIBYTE : S_MULTIBYTE;