git » libjio » commit f4f5446

Clarify some sanity checks in fill_trans()

author Alberto Bertogli
2009-03-02 00:37:53 UTC
committer Alberto Bertogli
2009-03-02 00:41:22 UTC
parent 5b2cc6ff1001a637c350a0491db7f44b2a32ec1b

Clarify some sanity checks in fill_trans()

This patch rewrites some of the checks in fill_trans() to make them more
clear and readable.

While at it, fix a minor coding style deviation.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>

check.c +3 -3

diff --git a/check.c b/check.c
index 4fd82b2..c430d14 100644
--- a/check.c
+++ b/check.c
@@ -44,7 +44,7 @@ static int fill_trans(unsigned char *map, off_t len, struct jtrans *ts)
 	p += 4;
 
 	for (i = 0; i < ts->numops; i++) {
-		if (len < (p - map) + J_DISKOPHEADSIZE)
+		if (p + J_DISKOPHEADSIZE > map + len)
 			goto error;
 
 		op = malloc(sizeof(struct joper));
@@ -60,7 +60,7 @@ static int fill_trans(unsigned char *map, off_t len, struct jtrans *ts)
 		op->offset = *( (uint64_t *) p);
 		p += 8;
 
-		if (len < (p - map) + op->len)
+		if (p + op->len > map + len)
 			goto error;
 
 		op->buf = (void *) p;
@@ -73,7 +73,7 @@ static int fill_trans(unsigned char *map, off_t len, struct jtrans *ts)
 			op->prev = NULL;
 			op->next = NULL;
 		} else {
-			for(tmp = ts->op; tmp->next != NULL; tmp = tmp->next)
+			for (tmp = ts->op; tmp->next != NULL; tmp = tmp->next)
 				;
 			tmp->next = op;
 			op->prev = tmp;