Skip to content

Commit

Permalink
bitcoin: use ccan/mem instead of rolling own check_mem function.
Browse files Browse the repository at this point in the history
Reported-by: John Newbery
Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Oct 26, 2015
1 parent be58e45 commit 6b2d844
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions bitcoin/shadouble.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "shadouble.h"
#include "valgrind.h"
#include <ccan/mem/mem.h>

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));
}

Expand Down
8 changes: 4 additions & 4 deletions bitcoin/tx.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include <ccan/crypto/sha256/sha256.h>
#include <ccan/endian/endian.h>
#include <ccan/err/err.h>
#include <ccan/mem/mem.h>
#include <ccan/read_write_all/read_write_all.h>
#include <ccan/str/hex/hex.h>
#include <ccan/tal/grab_file/grab_file.h>
#include <assert.h>
#include "tx.h"
#include "valgrind.h"

enum styles {
/* Add the CT padding stuff to amount. */
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 0 additions & 18 deletions bitcoin/valgrind.h

This file was deleted.

0 comments on commit 6b2d844

Please sign in to comment.