chiark / gitweb /
With "-s" specified, cope with empty or missing state file.
authorBen Harris <bjh21@bjh21.me.uk>
Wed, 14 Nov 2018 00:26:35 +0000 (00:26 +0000)
committerBen Harris <bjh21@bjh21.me.uk>
Wed, 14 Nov 2018 00:26:35 +0000 (00:26 +0000)
clunk.c

diff --git a/clunk.c b/clunk.c
index cbb8efb33f4cb6b660b81cfab543c01d90d43d2a..2ff3b4447b19c073e3342a8791db75c249aedbfd 100644 (file)
--- a/clunk.c
+++ b/clunk.c
@@ -100,8 +100,10 @@ init_statefile(char const *statefilename)
        len = pread(statefd, buf, 9, 0);
        if (len == -1)
                err(1, "read %s", optarg);
-       buf[len] = '\0';
-       init_statestring(buf);
+       if (len > 0) {
+               buf[len] = '\0';
+               init_statestring(buf);
+       }
 }
 
 static void