Skip to contentSkip to conversation

libfec: fix up pointer warnings in fec magic computation

PATCH Applied Mike Frysinger 2 participants 2 messages Sep 23, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libfec: fix up pointer warnings in fec magic computation

The current fec code casts a pointer to an int which causes warnings on 64bit systems. So create a macro for the duplicate/complicated magic computation, and add an unsigned long cast in it to fix the original problem.

---
 lib/libfec.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
lib/libfec.c +4 -3
index 924701f..b19ed6e 100644
@@ -629,12 +629,13 @@ struct fec_parms {
     int k, n ;		/* parameters of the code */
     gf *enc_matrix ;
 } ;
+#define COMP_FEC_MAGIC(fec) \
+	(((FEC_MAGIC ^ (fec)->k) ^ (fec)->n) ^ (unsigned long)((fec)->enc_matrix))
 
 void
 fec_free(struct fec_parms *p)
 {
-    if (p==NULL ||
-       p->magic != ( ( (FEC_MAGIC ^ p->k) ^ p->n) ^ (int)(p->enc_matrix)) ) {
+    if (p==NULL || p->magic != COMP_FEC_MAGIC(p)) {
 	fprintf(stderr, "bad parameters to fec_free\n");
 	return ;
     }
@@ -666,7 +667,7 @@ fec_new(int k, int n)
     retval->k = k ;
     retval->n = n ;
     retval->enc_matrix = NEW_GF_MATRIX(n, k);
-    retval->magic = ( ( FEC_MAGIC ^ k) ^ n) ^ (int)(retval->enc_matrix) ;
+    retval->magic = COMP_FEC_MAGIC(retval);
     tmp_m = NEW_GF_MATRIX(n, k);
     /*
      * fill the matrix with powers of field elements, starting from 0.
Signature · 1 line
1.7.3
#1 lore raw
Quoted 6 lines · Mike Frysinger

The current fec code casts a pointer to an int which causes warnings on 64bit systems. So create a macro for the duplicate/complicated magic computation, and add an unsigned long cast in it to fix the original problem.

Pushed to mtd-utils, thanks!

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)