isl_basic_set_opt: avoid invalid access on error path
[platform/upstream/isl.git] / isl_gmp.c
index 0622763..94119b6 100644 (file)
--- a/isl_gmp.c
+++ b/isl_gmp.c
@@ -1,19 +1,24 @@
-#include "isl_int.h"
+/*
+ * Copyright 2008-2009 Katholieke Universiteit Leuven
+ *
+ * Use of this software is governed by the MIT license
+ *
+ * Written by Sven Verdoolaege, K.U.Leuven, Departement
+ * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
+ */
 
-u_int32_t isl_gmp_hash(mpz_t v, u_int32_t hash)
+#include <isl/int.h>
+
+uint32_t isl_gmp_hash(mpz_t v, uint32_t hash)
 {
        int sa = v[0]._mp_size;
        int abs_sa = sa < 0 ? -sa : sa;
        unsigned char *data = (unsigned char *)v[0]._mp_d;
        unsigned char *end = data + abs_sa * sizeof(v[0]._mp_d[0]);
 
-       if (sa < 0) {
-               hash *= 16777619;
-               hash ^= 0xFF;
-       }
-       for (; data < end; ++data) {
-               hash *= 16777619;
-               hash ^= *data;
-       }
+       if (sa < 0)
+               isl_hash_byte(hash, 0xFF);
+       for (; data < end; ++data)
+               isl_hash_byte(hash, *data);
        return hash;
 }