diff mbox series

[v3,14/14] selftests/nolibc: enable compiler warnings

Message ID 20230803-nolibc-warnings-v3-14-bcc1a096ae02@weissschuh.net (mailing list archive)
State Accepted
Commit 45f65f8d04db6fa328ab8e0191a8b9462d4bad95
Headers show
Series tools/nolibc: enable compiler warnings | expand

Commit Message

Thomas Weißschuh Aug. 3, 2023, 7:28 a.m. UTC
It will help the developers to avoid cruft and detect some bugs.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 tools/testing/selftests/nolibc/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Willy Tarreau Aug. 5, 2023, 4:23 p.m. UTC | #1
On Thu, Aug 03, 2023 at 09:28:58AM +0200, Thomas Weißschuh wrote:
> It will help the developers to avoid cruft and detect some bugs.
> 
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> ---
>  tools/testing/selftests/nolibc/Makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile
> index b82d29b6c37f..e8d09cbee2ab 100644
> --- a/tools/testing/selftests/nolibc/Makefile
> +++ b/tools/testing/selftests/nolibc/Makefile
> @@ -79,7 +79,7 @@ endif
>  CFLAGS_s390 = -m64
>  CFLAGS_mips = -EL
>  CFLAGS_STACKPROTECTOR ?= $(call cc-option,-mstack-protector-guard=global $(call cc-option,-fstack-protector-all))
> -CFLAGS  ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 \
> +CFLAGS  ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 -W -Wall -Wextra \
>  		$(call cc-option,-fno-stack-protector) \
>  		$(CFLAGS_$(ARCH)) $(CFLAGS_STACKPROTECTOR)
>  LDFLAGS :=

I'm now getting this with gcc < 9:

  nolibc-test.c: In function 'test_pipe':
  nolibc-test.c:811:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (len != strlen(msg))
            ^
The reason is that len is ssize_t and strlen() is size_t. I tried different
approaches here but the cleanest remains turning len to size_t (we don't
use its sign anyway), so I'll do that one as well.

Cheers,
Willy
Willy Tarreau Aug. 5, 2023, 4:32 p.m. UTC | #2
On Sat, Aug 05, 2023 at 06:23:27PM +0200, Willy Tarreau wrote:
> On Thu, Aug 03, 2023 at 09:28:58AM +0200, Thomas Weißschuh wrote:
> > It will help the developers to avoid cruft and detect some bugs.
> > 
> > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> > ---
> >  tools/testing/selftests/nolibc/Makefile | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile
> > index b82d29b6c37f..e8d09cbee2ab 100644
> > --- a/tools/testing/selftests/nolibc/Makefile
> > +++ b/tools/testing/selftests/nolibc/Makefile
> > @@ -79,7 +79,7 @@ endif
> >  CFLAGS_s390 = -m64
> >  CFLAGS_mips = -EL
> >  CFLAGS_STACKPROTECTOR ?= $(call cc-option,-mstack-protector-guard=global $(call cc-option,-fstack-protector-all))
> > -CFLAGS  ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 \
> > +CFLAGS  ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 -W -Wall -Wextra \
> >  		$(call cc-option,-fno-stack-protector) \
> >  		$(CFLAGS_$(ARCH)) $(CFLAGS_STACKPROTECTOR)
> >  LDFLAGS :=
> 
> I'm now getting this with gcc < 9:
> 
>   nolibc-test.c: In function 'test_pipe':
>   nolibc-test.c:811:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
>     if (len != strlen(msg))
>             ^
> The reason is that len is ssize_t and strlen() is size_t. I tried different
> approaches here but the cleanest remains turning len to size_t (we don't
> use its sign anyway), so I'll do that one as well.

By the way since the original commit is still not upstream I'd rather
reinject this change directly in it. Yuan, are you OK with this ?

diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 0145a44af990..95884168cea0 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -798,7 +798,7 @@ int test_pipe(void)
 	const char *const msg = "hello, nolibc";
 	int pipefd[2];
 	char buf[32];
-	ssize_t len;
+	size_t len;
 
 	if (pipe(pipefd) == -1)

Thanks,
Willy
diff mbox series

Patch

diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile
index b82d29b6c37f..e8d09cbee2ab 100644
--- a/tools/testing/selftests/nolibc/Makefile
+++ b/tools/testing/selftests/nolibc/Makefile
@@ -79,7 +79,7 @@  endif
 CFLAGS_s390 = -m64
 CFLAGS_mips = -EL
 CFLAGS_STACKPROTECTOR ?= $(call cc-option,-mstack-protector-guard=global $(call cc-option,-fstack-protector-all))
-CFLAGS  ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 \
+CFLAGS  ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 -W -Wall -Wextra \
 		$(call cc-option,-fno-stack-protector) \
 		$(CFLAGS_$(ARCH)) $(CFLAGS_STACKPROTECTOR)
 LDFLAGS :=