git » libjio » commit edc7dc0

When we create the transaction file's header, we use sizeof() in memcpy and explicit sizes in the pointer arithmetic. As the sizes are not type-dependant but really fixed, defined in the on-disk format, this patch makes it more coherent by using the explicit sizes everywhere.

author Alberto Bertogli
2004-06-05 17:34:20 UTC
committer Alberto Bertogli
2007-07-15 13:02:29 UTC
parent 069b8bc6faaa8dedf9e72a259c98f62b7216bac8

When we create the transaction file's header, we use sizeof() in memcpy and explicit sizes in the pointer arithmetic. As the sizes are not type-dependant but really fixed, defined in the on-disk format, this patch makes it more coherent by using the explicit sizes everywhere.

When we create the transaction file's header, we use sizeof() in memcpy and
explicit sizes in the pointer arithmetic. As the sizes are not type-dependant
but really fixed, defined in the on-disk format, this patch makes it more
coherent by using the explicit sizes everywhere.

trans.c +8 -6

diff --git a/trans.c b/trans.c
index b250a1c..870c01a 100644
--- a/trans.c
+++ b/trans.c
@@ -240,22 +240,24 @@ int jtrans_commit(struct jtrans *ts)
 
 	bufp = buf_init;
 
-	memcpy(bufp, (void *) &(ts->id), sizeof(ts->id));
+	/* the sizes are put explicitly (instead of using sizeof()) because
+	 * they're really fixed and defined in the on-disk format */
+	memcpy(bufp, (void *) &(ts->id), 4);
 	bufp += 4;
 
-	memcpy(bufp, (void *) &(ts->flags), sizeof(ts->flags));
+	memcpy(bufp, (void *) &(ts->flags), 4);
 	bufp += 4;
 
-	memcpy(bufp, (void *) &(ts->len), sizeof(ts->len));
+	memcpy(bufp, (void *) &(ts->len), 4);
 	bufp += 4;
 
-	memcpy(bufp, (void *) &(ts->plen), sizeof(ts->plen));
+	memcpy(bufp, (void *) &(ts->plen), 4);
 	bufp += 4;
 
-	memcpy(bufp, (void *) &(ts->ulen), sizeof(ts->ulen));
+	memcpy(bufp, (void *) &(ts->ulen), 4);
 	bufp += 4;
 
-	memcpy(bufp, (void *) &(ts->offset), sizeof(ts->offset));
+	memcpy(bufp, (void *) &(ts->offset), 8);
 	bufp += 8;
 
 	rv = spwrite(fd, buf_init, J_DISKTFIXSIZE, 0);