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)
edge.strict_endians
Yura Pakhuchiy 2007-09-24 19:21:16 +03:00
parent a81520731c
commit 1b5fb2693c
3 changed files with 8 additions and 3 deletions

View File

@ -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) \

View File

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

View File

@ -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;