Repository: incubator-mynewt-core Updated Branches: refs/heads/develop 1449ffcdb -> 2bbb29106
MYNEWT-636; return error if there's magic mismatch on any fcb sector. 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/2bbb2910 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/2bbb2910 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/2bbb2910 Branch: refs/heads/develop Commit: 2bbb291068d8fe75c4df5f723c7d0d374dffee2b Parents: 1449ffc Author: Marko Kiiskila <ma...@runtime.io> Authored: Thu Feb 23 15:40:15 2017 -0800 Committer: Marko Kiiskila <ma...@runtime.io> Committed: Thu Feb 23 15:40:15 2017 -0800 ---------------------------------------------------------------------- fs/fcb/src/fcb.c | 5 ++++- fs/fcb/test/src/testcases/fcb_test_init.c | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2bbb2910/fs/fcb/src/fcb.c ---------------------------------------------------------------------- diff --git a/fs/fcb/src/fcb.c b/fs/fcb/src/fcb.c index 0a68be0..30c76b5 100644 --- a/fs/fcb/src/fcb.c +++ b/fs/fcb/src/fcb.c @@ -47,7 +47,10 @@ fcb_init(struct fcb *fcb) max_align = flash_area_align(fap); } rc = fcb_sector_hdr_read(fcb, fap, &fda); - if (rc <= 0) { + if (rc < 0) { + return rc; + } + if (rc == 0) { continue; } if (oldest < 0) { http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2bbb2910/fs/fcb/test/src/testcases/fcb_test_init.c ---------------------------------------------------------------------- diff --git a/fs/fcb/test/src/testcases/fcb_test_init.c b/fs/fcb/test/src/testcases/fcb_test_init.c index d3c33b4..68f3618 100644 --- a/fs/fcb/test/src/testcases/fcb_test_init.c +++ b/fs/fcb/test/src/testcases/fcb_test_init.c @@ -35,6 +35,11 @@ TEST_CASE(fcb_test_init) TEST_ASSERT(rc == FCB_ERR_ARGS); fcb->f_sector_cnt = 2; + fcb->f_magic = 0x12345678; + rc = fcb_init(fcb); + TEST_ASSERT(rc == FCB_ERR_MAGIC); + + fcb->f_magic = 0; rc = fcb_init(fcb); TEST_ASSERT(rc == 0); }