From a512e7dc1da4688f69189b4d234c9fcc188af2b2 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 10 Oct 2015 17:15:15 -0600 Subject: [PATCH] Fix a loop indexing problem in all file system tests --- examples/fstest/fstest_main.c | 21 +++++++++++---------- examples/nxffs/nxffs_main.c | 21 +++++++++++---------- examples/smart/smart_main.c | 21 +++++++++++---------- 3 files changed, 33 insertions(+), 30 deletions(-) diff --git a/examples/fstest/fstest_main.c b/examples/fstest/fstest_main.c index 4ce67c04a..8cc31b69d 100644 --- a/examples/fstest/fstest_main.c +++ b/examples/fstest/fstest_main.c @@ -619,10 +619,19 @@ static int fstest_delfiles(void) int ndx = (rand() % (g_nfiles - g_ndeleted)); - /* And delete the next undeleted file after that random index */ + /* And delete the next undeleted file after that random index. NOTE + * that the entry at ndx is not checked. + */ - for (j = ndx + 1; j != ndx;) + for (j = ndx + 1; j != ndx; j++) { + /* Test for wrap-around */ + + if (j >= CONFIG_EXAMPLES_FSTEST_MAXOPEN) + { + j = 0; + } + file = &g_files[j]; if (file->name && !file->deleted) { @@ -644,14 +653,6 @@ static int fstest_delfiles(void) break; } } - - /* Increment the index and test for wrap-around */ - - if (++j >= CONFIG_EXAMPLES_FSTEST_MAXOPEN) - { - j = 0; - } - } } diff --git a/examples/nxffs/nxffs_main.c b/examples/nxffs/nxffs_main.c index f3627b3c7..ddc15ee88 100644 --- a/examples/nxffs/nxffs_main.c +++ b/examples/nxffs/nxffs_main.c @@ -652,10 +652,19 @@ static int nxffs_delfiles(void) int ndx = (rand() % (g_nfiles - g_ndeleted)); - /* And delete the next undeleted file after that random index */ + /* And delete the next undeleted file after that random index. NOTE + * that the entry at ndx is not checked. + */ - for (j = ndx + 1; j != ndx;) + for (j = ndx + 1; j != ndx; j++) { + /* Test for wrap-around */ + + if (j >= CONFIG_EXAMPLES_FSTEST_MAXOPEN) + { + j = 0; + } + file = &g_files[j]; if (file->name && !file->deleted) { @@ -677,14 +686,6 @@ static int nxffs_delfiles(void) break; } } - - /* Increment the index and test for wrap-around */ - - if (++j >= CONFIG_EXAMPLES_NXFFS_MAXOPEN) - { - j = 0; - } - } } diff --git a/examples/smart/smart_main.c b/examples/smart/smart_main.c index cc53fb123..b189205b3 100644 --- a/examples/smart/smart_main.c +++ b/examples/smart/smart_main.c @@ -657,10 +657,19 @@ static int smart_delfiles(void) int ndx = (rand() % (g_nfiles - g_ndeleted)); - /* And delete the next undeleted file after that random index */ + /* And delete the next undeleted file after that random index. NOTE + * that the entry at ndx is not checked. + */ - for (j = ndx + 1; j != ndx;) + for (j = ndx + 1; j != ndx; j++) { + /* Test for wrap-around */ + + if (j >= CONFIG_EXAMPLES_FSTEST_MAXOPEN) + { + j = 0; + } + file = &g_files[j]; if (file->name && !file->deleted) { @@ -682,14 +691,6 @@ static int smart_delfiles(void) break; } } - - /* Increment the index and test for wrap-around */ - - if (++j >= CONFIG_EXAMPLES_SMART_MAXOPEN) - { - j = 0; - } - } }