Correct long-size bug that resulted in checksum error.
authorEric S. Raymond <esr@thyrsus.com>
Mon, 22 May 2017 13:30:51 +0000 (09:30 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Mon, 22 May 2017 13:30:51 +0000 (09:30 -0400)
Idea thanks tp Max Ninneman.

init.c
misc.c

diff --git a/init.c b/init.c
index 22622b72669df5fd6343462f565745fd23c41df6..1e4ec5e837a39dbf3ae174465084bcca7e0c0cd8 100644 (file)
--- a/init.c
+++ b/init.c
@@ -647,7 +647,7 @@ static bool quick_init(void) {
        init_reading = true;
        init_cksum = 1;
        quick_io();
-       if(fread(&K,4,1,f) == 1) init_cksum -= K; else init_cksum = 1;
+       if(fread(&K,sizeof(long),1,f) == 1) init_cksum -= K; else init_cksum = 1;
        fclose(f);
        if(init_cksum != 0)printf("Checksum error!\n");
        return(init_cksum == 0);
@@ -660,7 +660,7 @@ static void quick_save(void) {
        init_reading = false;
        init_cksum = 1;
        quick_io();
-       fwrite(&init_cksum,4,1,f);
+       fwrite(&init_cksum,sizeof(long),1,f);
        fclose(f);
 }
 
@@ -695,13 +695,13 @@ static void quick_io(void) {
 }
 
 static void quick_item(W)long *W; {
-       if(init_reading && fread(W,4,1,f) != 1)return;
+    if(init_reading && fread(W,sizeof(long),1,f) != 1)return;
        init_cksum = MOD(init_cksum*13+(*W),60000000);
-       if(!init_reading)fwrite(W,4,1,f);
+       if(!init_reading)fwrite(W,sizeof(long),1,f);
 }
 
 static void quick_array(A,N)long *A, N; { long I;
-       if(init_reading && fread(A,4,N+1,f) != N+1)printf("Read error!\n");
+       if(init_reading && fread(A,sizeof(long),N+1,f) != N+1)printf("Read error!\n");
        for(I=1;I<=N;I++)init_cksum = MOD(init_cksum*13+A[I],60000000);
-       if(!init_reading && fwrite(A,4,N+1,f)!=N+1)printf("Write error!\n");
+       if(!init_reading && fwrite(A,sizeof(long),N+1,f)!=N+1)printf("Write error!\n");
 }
diff --git a/misc.c b/misc.c
index 391b43c4d06eae816b5b6437f18614f6bf953480..711d9a976e398e7900d21384b877cabeb4fc2ed6 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -1004,8 +1004,8 @@ L20:      printf("\nFile name: ");
        if(F == NULL) {printf("Can't open file, try again.\n"); goto L20;}
        return;
 
-L30:   if(IN)IGNORE(fread(ARR,4,250,F));
-       if(!IN)fwrite(ARR,4,250,F);
+L30:   if(IN)IGNORE(fread(ARR,sizeof(long),250,F));
+       if(!IN)fwrite(ARR,sizeof(long),250,F);
        return;
 
 }