Repository: incubator-mynewt-core Updated Branches: refs/heads/develop 79e45a56b -> 46dad8f34
MYNEWT-709 nffs - Occasional unit test failures Fix a few uninitialized memory reads, as reported by valgrind. This probably doesn't fix the test failures. Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/46dad8f3 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/46dad8f3 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/46dad8f3 Branch: refs/heads/develop Commit: 46dad8f34272576ed46db666bfb4ec734bacb0ec Parents: 79e45a5 Author: Christopher Collins <ccoll...@apache.org> Authored: Tue Apr 4 19:29:27 2017 -0700 Committer: Christopher Collins <ccoll...@apache.org> Committed: Tue Apr 4 19:29:27 2017 -0700 ---------------------------------------------------------------------- fs/nffs/src/nffs_block.c | 1 + fs/nffs/src/nffs_file.c | 2 +- fs/nffs/src/nffs_gc.c | 2 -- fs/nffs/src/nffs_inode.c | 16 +++++----------- fs/nffs/src/nffs_restore.c | 2 ++ fs/nffs/src/nffs_write.c | 2 ++ 6 files changed, 11 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/46dad8f3/fs/nffs/src/nffs_block.c ---------------------------------------------------------------------- diff --git a/fs/nffs/src/nffs_block.c b/fs/nffs/src/nffs_block.c index 375f87e..30b6616 100644 --- a/fs/nffs/src/nffs_block.c +++ b/fs/nffs/src/nffs_block.c @@ -215,6 +215,7 @@ nffs_block_to_disk(const struct nffs_block *block, { assert(block->nb_inode_entry != NULL); + memset(out_disk_block, 0, sizeof *out_disk_block); out_disk_block->ndb_id = block->nb_hash_entry->nhe_id; out_disk_block->ndb_seq = block->nb_seq; out_disk_block->ndb_inode_id = http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/46dad8f3/fs/nffs/src/nffs_file.c ---------------------------------------------------------------------- diff --git a/fs/nffs/src/nffs_file.c b/fs/nffs/src/nffs_file.c index c542a66..bf1866f 100644 --- a/fs/nffs/src/nffs_file.c +++ b/fs/nffs/src/nffs_file.c @@ -89,7 +89,7 @@ nffs_file_new(struct nffs_inode_entry *parent, const char *filename, goto err; } - memset(&disk_inode, 0xff, sizeof disk_inode); + memset(&disk_inode, 0, sizeof disk_inode); if (is_dir) { disk_inode.ndi_id = nffs_hash_next_dir_id++; } else { http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/46dad8f3/fs/nffs/src/nffs_gc.c ---------------------------------------------------------------------- diff --git a/fs/nffs/src/nffs_gc.c b/fs/nffs/src/nffs_gc.c index 829a30f..8af1d2b 100644 --- a/fs/nffs/src/nffs_gc.c +++ b/fs/nffs/src/nffs_gc.c @@ -194,8 +194,6 @@ nffs_gc_block_chain_collate(struct nffs_hash_entry *last_entry, goto done; } - memset(&last_block, 0, sizeof(last_block)); - to_area = nffs_areas + to_area_idx; entry = last_entry; http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/46dad8f3/fs/nffs/src/nffs_inode.c ---------------------------------------------------------------------- diff --git a/fs/nffs/src/nffs_inode.c b/fs/nffs/src/nffs_inode.c index be614d8..2b38ab9 100644 --- a/fs/nffs/src/nffs_inode.c +++ b/fs/nffs/src/nffs_inode.c @@ -236,7 +236,8 @@ nffs_inode_from_entry(struct nffs_inode *out_inode, } if (cached_name_len != 0) { STATS_INC(nffs_stats, nffs_readcnt_inodeent); - rc = nffs_flash_read(area_idx, area_offset + sizeof disk_inode, out_inode->ni_filename, cached_name_len); + rc = nffs_flash_read(area_idx, area_offset + sizeof disk_inode, + out_inode->ni_filename, cached_name_len); if (rc != 0) { return rc; } @@ -277,16 +278,6 @@ nffs_inode_delete_blocks_from_ram(struct nffs_inode_entry *inode_entry) return 0; } - /* Dead comment?? XXX - * The block references something that does not exist in RAM. This - * is likely because the pointed-to object was in an area that has - * been garbage collected. Terminate the delete procedure and - * report success. - */ - /* XXX: This does not inspire confidence; the caller should somehow - * indicate that it expects this possibility. - */ - /** * Deletes the specified inode entry from the RAM representation. * @@ -473,6 +464,7 @@ nffs_inode_delete_from_disk(struct nffs_inode *inode) inode->ni_seq++; + memset(&disk_inode, 0, sizeof disk_inode); disk_inode.ndi_id = inode->ni_inode_entry->nie_hash_entry.nhe_id; disk_inode.ndi_seq = inode->ni_seq; disk_inode.ndi_parent_id = NFFS_ID_NONE; @@ -617,6 +609,7 @@ nffs_inode_rename(struct nffs_inode_entry *inode_entry, return rc; } + memset(&disk_inode, 0, sizeof disk_inode); disk_inode.ndi_id = inode_entry->nie_hash_entry.nhe_id; disk_inode.ndi_seq = inode.ni_seq + 1; disk_inode.ndi_parent_id = nffs_inode_parent_id(&inode); @@ -684,6 +677,7 @@ nffs_inode_update(struct nffs_inode_entry *inode_entry) return rc; } + memset(&disk_inode, 0, sizeof disk_inode); disk_inode.ndi_id = inode_entry->nie_hash_entry.nhe_id; disk_inode.ndi_seq = inode.ni_seq + 1; disk_inode.ndi_parent_id = nffs_inode_parent_id(&inode); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/46dad8f3/fs/nffs/src/nffs_restore.c ---------------------------------------------------------------------- diff --git a/fs/nffs/src/nffs_restore.c b/fs/nffs/src/nffs_restore.c index a40460c..0a3253c 100644 --- a/fs/nffs/src/nffs_restore.c +++ b/fs/nffs/src/nffs_restore.c @@ -977,6 +977,8 @@ nffs_restore_disk_object(int area_idx, uint32_t area_offset, { int rc; + memset(out_disk_object, 0, sizeof *out_disk_object); + rc = nffs_flash_read(area_idx, area_offset, &out_disk_object->ndo_un_obj, sizeof(out_disk_object->ndo_un_obj)); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/46dad8f3/fs/nffs/src/nffs_write.c ---------------------------------------------------------------------- diff --git a/fs/nffs/src/nffs_write.c b/fs/nffs/src/nffs_write.c index ea48e06..2ce2248 100644 --- a/fs/nffs/src/nffs_write.c +++ b/fs/nffs/src/nffs_write.c @@ -18,6 +18,7 @@ */ #include <assert.h> +#include <string.h> #include "testutil/testutil.h" #include "nffs/nffs.h" #include "nffs_priv.h" @@ -225,6 +226,7 @@ nffs_write_append(struct nffs_cache_inode *cache_inode, const void *data, inode_entry = cache_inode->nci_inode.ni_inode_entry; + memset(&disk_block, 0, sizeof disk_block); disk_block.ndb_id = nffs_hash_next_block_id++; disk_block.ndb_seq = 0; disk_block.ndb_inode_id = inode_entry->nie_hash_entry.nhe_id;