From 6b2d844f2a3e322095adf502ccf47d2f9cda220a Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 26 Oct 2015 21:05:28 +1030 Subject: [PATCH] bitcoin: use ccan/mem instead of rolling own check_mem function. Reported-by: John Newbery Signed-off-by: Rusty Russell --- Makefile | 2 +- bitcoin/shadouble.c | 4 ++-- bitcoin/tx.c | 8 ++++---- bitcoin/valgrind.h | 18 ------------------ 4 files changed, 7 insertions(+), 25 deletions(-) delete mode 100644 bitcoin/valgrind.h diff --git a/Makefile b/Makefile index 2509cb6cc..969f398a3 100644 --- a/Makefile +++ b/Makefile @@ -88,7 +88,7 @@ PROGRAMS := $(TEST_CLI_PROGRAMS) $(TEST_PROGRAMS) HEADERS := $(filter-out gen_*, $(wildcard *.h)) $(wildcard bitcoin/*.h) gen_state_names.h CCANDIR := ccan/ -CFLAGS := -g -Wall -I $(CCANDIR) -I secp256k1/include/ -DVALGRIND_HEADERS=1 $(FEATURES) +CFLAGS := -g -Wall -I $(CCANDIR) -I secp256k1/include/ $(FEATURES) LDLIBS := -lcrypto -lprotobuf-c $(PROGRAMS): CFLAGS+=-I. diff --git a/bitcoin/shadouble.c b/bitcoin/shadouble.c index b8897e58e..c229b9744 100644 --- a/bitcoin/shadouble.c +++ b/bitcoin/shadouble.c @@ -1,9 +1,9 @@ #include "shadouble.h" -#include "valgrind.h" +#include void sha256_double(struct sha256_double *shadouble, const void *p, size_t len) { - sha256(&shadouble->sha, check_mem(p, len), len); + sha256(&shadouble->sha, memcheck(p, len), len); sha256(&shadouble->sha, &shadouble->sha, sizeof(shadouble->sha)); } diff --git a/bitcoin/tx.c b/bitcoin/tx.c index 97c59f26c..00799525a 100644 --- a/bitcoin/tx.c +++ b/bitcoin/tx.c @@ -1,12 +1,12 @@ #include #include #include +#include #include #include #include #include #include "tx.h" -#include "valgrind.h" enum styles { /* Add the CT padding stuff to amount. */ @@ -197,7 +197,7 @@ static void add_tx(const struct bitcoin_tx *tx, static void add_sha(const void *data, size_t len, void *shactx_) { struct sha256_ctx *ctx = shactx_; - sha256_update(ctx, check_mem(data, len), len); + sha256_update(ctx, memcheck(data, len), len); } void sha256_tx_for_sig(struct sha256_ctx *ctx, const struct bitcoin_tx *tx, @@ -219,7 +219,7 @@ static void add_linearize(const void *data, size_t len, void *pptr_) size_t oldsize = tal_count(*pptr); tal_resize(pptr, oldsize + len); - memcpy(*pptr + oldsize, check_mem(data, len), len); + memcpy(*pptr + oldsize, memcheck(data, len), len); } u8 *linearize_tx(const tal_t *ctx, const struct bitcoin_tx *tx) @@ -278,7 +278,7 @@ static const u8 *pull(const u8 **cursor, size_t *max, void *copy, size_t n) *max -= n; if (copy) memcpy(copy, p, n); - return check_mem(p, n); + return memcheck(p, n); } static u64 pull_varint(const u8 **cursor, size_t *max) diff --git a/bitcoin/valgrind.h b/bitcoin/valgrind.h deleted file mode 100644 index 11fbb1696..000000000 --- a/bitcoin/valgrind.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef LIGHTNING_VALGRIND_H -#define LIGHTNING_VALGRIND_H - -#ifdef VALGRIND_HEADERS -#include -#elif !defined(VALGRIND_CHECK_MEM_IS_DEFINED) -#define VALGRIND_CHECK_MEM_IS_DEFINED(p, len) -#define RUNNING_ON_VALGRIND 0 -#endif - -/* Useful for hashing: makes sure we're not hashing crap *before* we use - * the hash value for something. */ -static inline void *check_mem(const void *data, size_t len) -{ - VALGRIND_CHECK_MEM_IS_DEFINED(data, len); - return (void *)data; -} -#endif /* LIGHTNING_VALGRIND_H */