diff --git a/C/save.c b/C/save.c
index c53722110..33ca7e3c8 100644
--- a/C/save.c
+++ b/C/save.c
@@ -184,7 +184,7 @@ myread(int fd, char *buff, Int len)
{
while (len > 0) {
int nchars = read(fd, buff, len);
- if (nchars < 0) {
+ if (nchars <= 0) {
return do_system_error(PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM, "bad read on saved state");
}
len -= nchars;
@@ -617,11 +617,13 @@ check_header(CELL *info, CELL *ATrail, CELL *AStack, CELL *AHeap)
char pp[80];
char msg[256];
CELL hp_size, gb_size, lc_size, tr_size, mode;
+ int n;
/* make sure we always check if there are enough bytes */
/* skip the first line */
+ pp[0] = '\0';
do {
- if (read(splfild, pp, 1) < 0) {
+ if ((n = read(splfild, pp, 1)) <= 0) {
do_system_error(PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM,"failed to scan first line from saved state");
return FAIL_RESTORE;
}
@@ -631,7 +633,7 @@ check_header(CELL *info, CELL *ATrail, CELL *AStack, CELL *AHeap)
{
int count = 0, n, to_read = Unsigned(strlen(msg) + 1);
while (count < to_read) {
- if ((n = read(splfild, pp, to_read-count)) < 0) {
+ if ((n = read(splfild, pp, to_read-count)) <= 0) {
do_system_error(PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM,"failed to scan version info from saved state");
return FAIL_RESTORE;
}
@@ -909,7 +911,7 @@ CopyCode(void)
/* skip the local and global data structures */
CELL j = get_cell();
if (Yap_ErrorMessage)
- return -1;
+ return -1;
if (j != Unsigned(&GLOBAL) - Unsigned(Yap_HeapBase)) {
Yap_ErrorMessage = "code space size does not match saved state";
return -1;
diff --git a/changes-5.1.html b/changes-5.1.html
index 828c6e35f..26003ad60 100644
--- a/changes-5.1.html
+++ b/changes-5.1.html
@@ -16,6 +16,8 @@
Yap-5.1.2:
+- FIXED: -l and -L options (again?).
+- FIXED: if we cannot read more chars in saved state we're dead.
- FIXED: termination info for failed and detached threads (obs Paulo Moura).
- FIXED: check_callable should check for modules (obs Paulo Moura).
- NEW: add thread_sleep/1, mostly works like system:sleep/1 (request from Paulo Moura).
diff --git a/console/yap.c b/console/yap.c
index 9c4b24107..e19d426fd 100644
--- a/console/yap.c
+++ b/console/yap.c
@@ -433,47 +433,33 @@ parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap)
break;
#endif
case 'L':
- p++;
iap->HaltAfterConsult = TRUE;
- if (*p != '\0') {
- iap->YapPrologRCFile = p;
- break;
- } else {
- if (--argc == 0) {
- fprintf(stderr,
- " [ YAP unrecoverable error: missing file name with option 'L' ]\n");
- exit(1);
- }
- p = *++argv;
- if (p[0] == '-' && p[1] == '-' && p[2] == '\0') {
- if (--argc == 0) {
- fprintf(stderr,
- " [ YAP unrecoverable error: missing filename with option 'L' ]\n");
- exit(1);
- }
- p = *++argv;
- iap->YapPrologRCFile = p;
- argc = 1;
-
- } else {
- iap->YapPrologRCFile = p;
- }
- }
- break;
case 'l':
- if ((*argv)[0] == '\0')
- iap->YapPrologRCFile = *argv;
- else {
- argc--;
- if (argc == 0) {
- fprintf(stderr," [ YAP unrecoverable error: missing file name with option 'l' ]\n");
- exit(EXIT_FAILURE);
- }
- argv++;
- iap->YapPrologRCFile = *argv;
- }
- break;
- /* run goal before top-level */
+ p++;
+ if (!*++argv) {
+ fprintf(stderr,
+ "%% YAP unrecoverable error: missing boot file name\n");
+ exit(1);
+ } else {
+ iap->YapPrologRCFile = *argv;
+ argc--;
+ }
+ if (*p) {
+ /* we have something, usually, of the form:
+ -L --
+ FileName
+ ExtraArgs
+ */
+ /* being called from a script */
+ while (*p && (*p == ' ' || *p == '\t'))
+ p++;
+ if (p[0] == '-' && p[1] == '-') {
+ /* ignore what is next */
+ argc = 1;
+ }
+ }
+ break;
+ /* run goal before top-level */
case 'g':
if ((*argv)[0] == '\0')
iap->YapPrologGoal = *argv;