From 0e26ab464b31efade58e9a9f850f464a8c728e3c Mon Sep 17 00:00:00 2001 From: patacongo Date: Mon, 31 Oct 2011 20:23:17 +0000 Subject: [PATCH] Fix another NXFFS write-when-flash-is-full problem git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4075 42af7a65-404d-4744-a932-0658087f49c3 --- examples/nxffs/nxffs_main.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/examples/nxffs/nxffs_main.c b/examples/nxffs/nxffs_main.c index e201f0802..863f8bb43 100644 --- a/examples/nxffs/nxffs_main.c +++ b/examples/nxffs/nxffs_main.c @@ -2,7 +2,7 @@ * examples/nxffs/nxffs_main.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -642,9 +642,17 @@ static int nxffs_delfiles(void) int i; int j; - /* How many files should we delete? */ + /* Are there any files to be deleted? */ - ndel = (rand() % (g_nfiles - g_ndeleted)) + 1; + int nfiles = g_nfiles - g_ndeleted; + if (nfiles < 1) + { + return 0; + } + + /* Yes... How many files should we delete? */ + + ndel = (rand() % nfiles) + 1; /* Now pick which files to delete */