2020-10-26 10:17:33

by Robin Hsu

[permalink] [raw]
Subject: [PATCH 1/1] f2fs-toos:fsck.f2fs Fix bad return value

'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 <[email protected]>
---
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))
--
2.29.0.rc2.309.g374f81d7ae-goog


2020-10-29 08:45:12

by Chao Yu

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

On 2020/10/26 17:40, 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 <[email protected]>

BTW, how about changing 'ret = EXIT_ERR_CODE' to
'ret = FSCK_ERRORS_LEFT_UNCORRECTED', it's not critical though.

Reviewed-by: Chao Yu <[email protected]>

Thanks,

2020-11-02 16:13:27

by Jaegeuk Kim

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

On 10/28, Chao Yu wrote:
> On 2020/10/26 17:40, 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 <[email protected]>
>
> BTW, how about changing 'ret = EXIT_ERR_CODE' to
> 'ret = FSCK_ERRORS_LEFT_UNCORRECTED', it's not critical though.
>
> Reviewed-by: Chao Yu <[email protected]>

I think it'd be good to go as is for now. :)

>
> Thanks,

2020-11-03 02:56:58

by Eric Biggers

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

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 <[email protected]>
> ---
> 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);
^~~~~~

2020-11-03 03:26:12

by Jaegeuk Kim

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

On 11/02, Eric Biggers wrote:
> 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 <[email protected]>
> > ---
> > 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);
> ^~~~~~

Urg. Fixed by this.

From c986140e3c5abb9eb7a08928a88acb8273f1bd52 Mon Sep 17 00:00:00 2001
From: Robin Hsu <[email protected]>
Date: Mon, 26 Oct 2020 17:40:00 +0800
Subject: [PATCH] f2fs-toos: fsck.f2fs Fix bad return value

'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 <[email protected]>
Reviewed-by: Chao Yu <[email protected]>
Signed-off-by: Jaegeuk Kim <[email protected]>
---
fsck/fsck.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fsck/fsck.c b/fsck/fsck.c
index 647523397f3e..e52672032d2c 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -3146,10 +3146,11 @@ int fsck_verify(struct f2fs_sb_info *sbi)
#ifndef WITH_ANDROID
if (nr_unref_nid && !c.ro) {
char ans[255] = {0};
+ int res;

printf("\nDo you want to restore lost files into ./lost_found/? [Y/N] ");
- ret = scanf("%s", ans);
- ASSERT(ret >= 0);
+ res = scanf("%s", ans);
+ ASSERT(res >= 0);
if (!strcasecmp(ans, "y")) {
for (i = 0; i < fsck->nr_nat_entries; i++) {
if (f2fs_test_bit(i, fsck->nat_area_bitmap))
--
2.29.1.341.ge80a0c044ae-goog