On Mon, Jun 09, 2014 at 09:16:42PM +0200, Tobias Stoeckmann wrote:
> +                     cl++;
[...]
> +                     *p |= (u_char)(fat[cl + 1].next << 4);
> +                     *p++ = (u_char)(fat[cl + 1].next >> 4);

And here the correct diff, cl + 1 must not be done after cl++ ...

Index: fat.c
===================================================================
RCS file: /cvs/src/sbin/fsck_msdos/fat.c,v
retrieving revision 1.19
diff -u -p -r1.19 fat.c
--- fat.c       9 Jun 2014 09:13:33 -0000       1.19
+++ fat.c       9 Jun 2014 19:06:26 -0000
@@ -471,13 +471,15 @@ writefat(int fs, struct bootblock *boot,
                default:
                        if (fat[cl].next == CLUST_FREE)
                                boot->NumFree++;
-                       if (cl + 1 < boot->NumClusters
-                           && fat[cl + 1].next == CLUST_FREE)
-                               boot->NumFree++;
                        *p++ = (u_char)fat[cl].next;
-                       *p++ = (u_char)((fat[cl].next >> 8) & 0xf)
-                              |(u_char)(fat[cl+1].next << 4);
-                       *p++ = (u_char)(fat[++cl].next >> 4);
+                       *p++ = (u_char)((fat[cl].next >> 8) & 0xf);
+                       cl++;
+                       if (cl >= boot->NumClusters)
+                               break;
+                       if (fat[cl].next == CLUST_FREE)
+                               boot->NumFree++;
+                       *p |= (u_char)(fat[cl].next << 4);
+                       *p++ = (u_char)(fat[cl].next >> 4);
                        break;
                }
        }

Reply via email to