Re: [f2fs-dev] [PATCH 1/1] f2fs-toos:fsck.f2fs Fix bad return value

From: Eric Biggers
Date: Mon Nov 02 2020 - 21:52:51 EST


On Mon, Oct 26, 2020 at 05:40:00PM +0800, Robin Hsu via Linux-f2fs-devel wrote:
> 'ret' should not have been used here: otherwise, it would be wrongly used
> as the error code and then be returned from main().
>
> Signed-off-by: Robin Hsu <robinhsu@xxxxxxxxxx>
> ---
> fsck/fsck.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/fsck/fsck.c b/fsck/fsck.c
> index f97e9fb..66e4e3f 100644
> --- a/fsck/fsck.c
> +++ b/fsck/fsck.c
> @@ -3137,8 +3137,7 @@ int fsck_verify(struct f2fs_sb_info *sbi)
> char ans[255] = {0};
>
> printf("\nDo you want to restore lost files into ./lost_found/? [Y/N] ");
> - ret = scanf("%s", ans);
> - ASSERT(ret >= 0);
> + ASSERT(scanf("%s", ans) >= 0);
> if (!strcasecmp(ans, "y")) {
> for (i = 0; i < fsck->nr_nat_entries; i++) {
> if (f2fs_test_bit(i, fsck->nat_area_bitmap))

This patch causes a compiler warning:

In file included from f2fs.h:33,
from fsck.h:14,
from fsck.c:11:
fsck.c: In function 'fsck_verify':
../include/f2fs_fs.h:197:11: warning: format '%s' expects a matching 'char *' argument [-Wformat=]
printf("[ASSERT] (%s:%4d) " #exp"\n", \
^~~~~~~~~~~~~~~~~~~~
fsck.c:3151:3: note: in expansion of macro 'ASSERT'
ASSERT(scanf("%s", ans) >= 0);
^~~~~~