aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2010-02-24 22:29:19 +1100
committerJon Loeliger <jdl@jdl.com>2010-02-24 08:50:25 -0600
commit716418849a0ed4cc7689d4b82a73597a8726de92 (patch)
tree4083fe6df20bc6734a879de38710aade02b782b1
parent05898c67c15d73fe50bd87fc939bd9ee6a4275ce (diff)
downloaddtc-716418849a0ed4cc7689d4b82a73597a8726de92.tar.gz
dtc: Audit and fix valgrind errors
The somewhat embarrasing bug in the first version of my previous patch would have been detected by valgrind. Thus reminded, I've run the testsuite under valgrind and fixed any errors I found. This turned out to be just some uninitialized buffers in test programs. The fragments of uninitialized data aren't particularly important, but we might as well squash the valgrind warnings, so that future valgrind errors will stand out. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
-rw-r--r--tests/mangle-layout.c7
-rw-r--r--tests/open_pack.c2
2 files changed, 6 insertions, 3 deletions
diff --git a/tests/mangle-layout.c b/tests/mangle-layout.c
index 5be28b9..3b19788 100644
--- a/tests/mangle-layout.c
+++ b/tests/mangle-layout.c
@@ -65,7 +65,7 @@ static void new_header(struct bufstate *buf, int version, const void *fdt)
static void add_block(struct bufstate *buf, int version, char block, const void *fdt)
{
- int align, size;
+ int align, size, oldsize;
const void *src;
int offset;
@@ -95,9 +95,10 @@ static void add_block(struct bufstate *buf, int version, char block, const void
CONFIG("Bad block '%c'", block);
}
- offset = ALIGN(buf->size, align);
-
+ oldsize = buf->size;
+ offset = ALIGN(oldsize, align);
expand_buf(buf, offset+size);
+ memset(buf->buf + oldsize, 0, offset - oldsize);
memcpy(buf->buf + offset, src, size);
diff --git a/tests/open_pack.c b/tests/open_pack.c
index d614024..0a5a3fc 100644
--- a/tests/open_pack.c
+++ b/tests/open_pack.c
@@ -48,6 +48,8 @@ int main(int argc, char *argv[])
bufsize = oldsize * 2;
buf = xmalloc(bufsize);
+ /* don't leak uninitialized memory into our output */
+ memset(buf, 0, bufsize);
fdt1 = buf;
err = fdt_open_into(fdt, fdt1, bufsize);