From 1b5fb2693cc59c071edb627ee2d952e83d473543 Mon Sep 17 00:00:00 2001 From: Yura Pakhuchiy Date: Mon, 24 Sep 2007 19:21:16 +0300 Subject: [PATCH] Introduce NTFS_ON_DEBUG macro to add one-liners which would be executed only if DEBUG is defined. And use it to shut up valgrind crying about writing of unitialized buffer (we do not initialize part of attribute list left for padding) --- include/ntfs/debug.h | 2 ++ libntfs/attrlist.c | 4 ++-- libntfs/inode.c | 5 ++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/ntfs/debug.h b/include/ntfs/debug.h index bf456f12..e46c8559 100644 --- a/include/ntfs/debug.h +++ b/include/ntfs/debug.h @@ -32,8 +32,10 @@ struct _runlist_element; #ifndef DEBUG static __inline__ void ntfs_debug_runlist_dump(const struct _runlist_element *rl __attribute__((unused))) {} +#define NTFS_ON_DEBUG(x) #else extern void ntfs_debug_runlist_dump(const struct _runlist_element *rl); +#define NTFS_ON_DEBUG(x) (x) #endif #define NTFS_BUG(msg) \ diff --git a/libntfs/attrlist.c b/libntfs/attrlist.c index ce171bf9..33b56062 100644 --- a/libntfs/attrlist.c +++ b/libntfs/attrlist.c @@ -185,8 +185,6 @@ int ntfs_attrlist_entry_add(ntfs_inode *ni, ATTR_RECORD *attr) entry_offset = ((u8 *)ale - ni->attr_list); /* Set pointer to new entry. */ ale = (ATTR_LIST_ENTRY *)(new_al + entry_offset); - /* Zero it to fix valgrind warning. */ - memset(ale, 0, entry_len); /* Form new entry. */ ale->type = attr->type; ale->length = cpu_to_le16(entry_len); @@ -198,6 +196,8 @@ int ntfs_attrlist_entry_add(ntfs_inode *ni, ATTR_RECORD *attr) ale->lowest_vcn = 0; ale->mft_reference = mref; ale->instance = attr->instance; + NTFS_ON_DEBUG(memset(ale->name, 0, ((u8*)((u8*)ale + entry_len)) - + ((u8*)ale->name))); /* Shut up, valgrind. */ memcpy(ale->name, (u8 *)attr + le16_to_cpu(attr->name_offset), attr->name_length * sizeof(ntfschar)); diff --git a/libntfs/inode.c b/libntfs/inode.c index 87f08464..6e1681d4 100644 --- a/libntfs/inode.c +++ b/libntfs/inode.c @@ -831,6 +831,7 @@ int ntfs_inode_add_attrlist(ntfs_inode *ni) al_allocated = 0x40; al_len = 0; al = malloc(al_allocated); + NTFS_ON_DEBUG(memset(al, 0, 0x40)); /* Valgrind. */ ale = (ATTR_LIST_ENTRY *) al; if (!al) { ntfs_log_trace("Not enough memory.\n"); @@ -849,7 +850,7 @@ int ntfs_inode_add_attrlist(ntfs_inode *ni) while (!ntfs_attr_lookup(AT_UNUSED, NULL, 0, 0, 0, NULL, 0, ctx)) { if (ctx->attr->type == AT_ATTRIBUTE_LIST) { err = EIO; - ntfs_log_trace("Eeek! Attribute list already present.\n"); + ntfs_log_trace("Attribute list already present.\n"); goto put_err_out; } /* Calculate new length of attribute list. */ @@ -859,6 +860,8 @@ int ntfs_inode_add_attrlist(ntfs_inode *ni) while (al_len > al_allocated) { al_allocated += 0x40; aln = realloc(al, al_allocated); + NTFS_ON_DEBUG(memset(aln + al_allocated - 0x40, 0, + 0x40)); /* Valgrind. */ if (!aln) { ntfs_log_trace("Not enough memory.\n"); err = ENOMEM;