]> git.neil.brown.name Git - LaFS.git/commitdiff
walk_extent: don't keep walking past the end of the list of addresses
authorNeilBrown <neilb@suse.de>
Tue, 8 Jun 2010 08:15:54 +0000 (18:15 +1000)
committerNeilBrown <neilb@suse.de>
Tue, 8 Jun 2010 08:15:54 +0000 (18:15 +1000)
Once we find a len of 0, there is nothing more worth finding.

Signed-off-by: NeilBrown <neilb@suse.de>
modify.c

index 2d88024ffe33a1f89938fece98f45ccf45b0ca63..0508e61a4791c72279cf7aaf67937a782ba81884 100644 (file)
--- a/modify.c
+++ b/modify.c
@@ -878,22 +878,30 @@ static u32 walk_extent(char **bufp, int len, struct uninc *ui,
        u64 ephys = 0;
        u32 eaddr = 0;
        int elen = 0;
+       int found_end = 0;
        int handled;
        char *buf = *bufp;
 
        handle(data, 0, 0, len); /* initialise */
 
-       while (len >= 12 || uinum < ui->pending_cnt || elen) {
+       while (uinum < ui->pending_cnt || ! found_end) {
 
-               if (elen == 0) {
+               if (elen == 0 && !found_end) {
                        if (len >= 12) {
                                ephys = decode48(buf);
                                elen = decode16(buf);
                                eaddr = decode32(buf);
                                len -= 12;
                                BUG_ON(ephys == 0 && elen != 0); // FIXME fail gracefully
-                       } else
+                               if (ephys == 0) {
+                                       eaddr = 0xFFFFFFFFUL;
+                                       found_end = 1;
+                               }
+                       } else {
                                eaddr = 0xFFFFFFFFUL;
+                               elen = 0;
+                               found_end = 1;
+                       }
                }
 
                /* Handle all pending extents that start before (or at) here */