diff --git a/src/files.c b/src/files.c
index 9ecad057c58723a5eb0eb1158878adbe5d4c12be..205f18edf038e19ac01680abcb2ea41ac8dadac1 100644
--- a/src/files.c
+++ b/src/files.c
@@ -3192,7 +3192,11 @@ void load_poshistory(void)
 
 	    /* Find where the x index and line number are in the line. */
 	    xptr = revstrstr(line, " ", line + read - 3);
+	    if (xptr == NULL)
+		continue;
 	    lineptr = revstrstr(line, " ", xptr - 2);
+	    if (lineptr == NULL)
+		continue;
 
 	    /* Now separate the three elements of the line. */
 	    *(xptr++) = '\0';