From: NeilBrown Date: Wed, 23 Jun 2010 01:52:00 +0000 (+1000) Subject: lafs_space_alloc - avoid underflow of unsigned numbers X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=b1131836a7cf73af33ccacc73b29a2bde11f417c;p=LaFS.git lafs_space_alloc - avoid underflow of unsigned numbers As the numbers in the calc are unsigned, use only additions to avoid anything going negative. Signed-off-by: NeilBrown --- diff --git a/segments.c b/segments.c index 4e2ae3a..ffed5c4 100644 --- a/segments.c +++ b/segments.c @@ -615,8 +615,8 @@ int lafs_space_alloc(struct fs *fs, int credits, int why) * EAGAIN, so never return it */ if (fs->rolled) { - if (fs->free_blocks - fs->allocated_blocks - - credits < watermark) + if (fs->free_blocks < fs->allocated_blocks + + credits + watermark) credits = 0; /* Sorry, no room */ } }