X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb/blobdiff_plain/aaae9cab01b8d7a0e6cf0c273182a51fd03a9d61..379829cb2ac6ab1e6f23ee5b5bfa16c96f111c3a:/symm/hash.h?ds=sidebyside diff --git a/symm/hash.h b/symm/hash.h index f4925184..eb3cd75e 100644 --- a/symm/hash.h +++ b/symm/hash.h @@ -68,10 +68,10 @@ \ { \ uint32 _l = U32(_bsz); \ - uint32 _h = ((_bsz & ~MASK32) >> 16) >> 16; \ + uint32 _h = ((_bsz & ~(size_t)MASK32) >> 16) >> 16; \ _bctx->nh += _h; \ _bctx->nl += _l; \ - if (_bctx->nl < _l || _bctx->nl & ~MASK32) \ + if (_bctx->nl < _l || _bctx->nl & ~(uint32)MASK32) \ _bctx->nh++; \ } \ \ @@ -165,9 +165,11 @@ #define HASH_BUFLEN 100000 -#define HASH_TESTX(PRE, pre, name, fname) \ +#define HASH_VERIFY(PRE, pre) HASH_VERIFYX(PRE, pre, #pre) + +#define HASH_VERIFYX(PRE, pre, name) \ \ -static int verify(dstr *v) \ +static int vrf_##pre(dstr *v, const test_type *msgty) \ { \ pre##_ctx ctx; \ int ok = 1; \ @@ -199,8 +201,9 @@ static int verify(dstr *v) \ } \ pre##_done(&ctx, d.buf); \ if (memcmp(d.buf, v[1].buf, PRE##_HASHSZ) != 0) { \ - printf("\nfail:\n\tstep = %i\n\tinput = `%s'\n\texpected = ", \ - *ip, v[0].buf); \ + printf("\nfail:\n\tstep = %i\n\tinput = ", *ip); \ + msgty->dump(&v[0], stdout); \ + printf("\n\texpected = "); \ type_hex.dump(&v[1], stdout); \ fputs("\n\tcomputed = ", stdout); \ type_hex.dump(&d, stdout); \ @@ -213,7 +216,12 @@ static int verify(dstr *v) \ return (ok); \ } \ \ -static int verifyrep(dstr *v) \ +static int vrf_##pre##_hex(dstr *v) \ + { return vrf_##pre(v, &type_hex); } \ +static int vrf_##pre##_lit(dstr *v) \ + { return vrf_##pre(v, &type_string); } \ + \ +static int vrf_##pre##_rep(dstr *v) \ { \ pre##_ctx ctx; \ size_t len = v[0].len; \ @@ -248,12 +256,22 @@ static int verifyrep(dstr *v) \ xfree(p); \ dstr_destroy(&d); \ return (ok); \ -} \ +} + +#define HASH_TESTDEFS(PRE, pre) HASH_TESTDEFSX(PRE, pre, #pre) + +#define HASH_TESTDEFSX(PRE, pre, name) \ + { name, vrf_##pre##_lit, { &type_string, &type_hex, 0 } }, \ + { name "-hex", vrf_##pre##_hex, { &type_hex, &type_hex, 0 } }, \ + { name "-rep", vrf_##pre##_rep, \ + { &type_string, &type_int, &type_hex, 0 } }, + +#define HASH_TESTX(PRE, pre, name, fname) \ + \ +HASH_VERIFYX(PRE, pre, name) \ \ static test_chunk defs[] = { \ - { name, verify, { &type_string, &type_hex, 0 } }, \ - { name "-rep", verifyrep, \ - { &type_string, &type_int, &type_hex, 0 } }, \ + HASH_TESTDEFSX(PRE, pre, name) \ { 0, 0, { 0 } } \ }; \ \