Message ID | 20210124065437.33283-1-thuth@redhat.com |
---|---|
State | Superseded |
Headers | show |
Series | Compile SLOF with -Wimplicit-fallthrough | expand |
Hi Thomas, On Sun, Jan 24, 2021 at 7:54 AM Thomas Huth <thuth@redhat.com> wrote: > > The -Wimplicit-fallthrough warnings help to catch bugs with forgotten > "break" statements, so it's a good idea to have this switch enabled. > Thus let's fix the current spots that generate warnings and add the > switch to our WARNFLAGS. > > Signed-off-by: Thomas Huth <thuth@redhat.com> > --- > lib/libc/stdio/vsnprintf.c | 1 + > make.rules | 4 +++- > slof/prim.code | 3 +++ > 3 files changed, 7 insertions(+), 1 deletion(-) I'd rather have 2 distinct patches, first C code, then buildsys. Since I don't know the SLOF project preferences, up to you :) In any case (this, or split in 2 patches): Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Thanks, Phil.
diff --git a/lib/libc/stdio/vsnprintf.c b/lib/libc/stdio/vsnprintf.c index 21dd04d..23e6dd4 100644 --- a/lib/libc/stdio/vsnprintf.c +++ b/lib/libc/stdio/vsnprintf.c @@ -163,6 +163,7 @@ print_format(char **buffer, size_t bufsize, const char *format, void *var) break; case 'X': upper = true; + /* fallthrough */ case 'x': sizec[i] = '\0'; value = (unsigned long) var & convert[length_mod]; diff --git a/make.rules b/make.rules index 3dfbb5b..a66f9be 100644 --- a/make.rules +++ b/make.rules @@ -76,7 +76,9 @@ AR ?= $(CROSS)ar RANLIB ?= $(CROSS)ranlib CPP ?= $(CROSS)cpp -WARNFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -Wformat-security +WARNFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -Wformat-security \ + -Wimplicit-fallthrough + CFLAGS ?= -g -O2 -fno-builtin -ffreestanding -nostdinc -msoft-float \ -fno-strict-aliasing -mno-altivec -mabi=no-altivec \ -fno-stack-protector -fno-asynchronous-unwind-tables $(WARNFLAGS) diff --git a/slof/prim.code b/slof/prim.code index bb9e036..b9db151 100644 --- a/slof/prim.code +++ b/slof/prim.code @@ -469,18 +469,21 @@ code_FILL: #endif while ((size-=sizeof(type_u)) >= 0) *up++ = fill_v; + break; } case sizeof(type_l): { type_l *lp = (type_l *)d; while ((size-=sizeof(type_l)) >= 0) *lp++ = (type_l)fill_v; + break; } case sizeof(type_w): { type_w *wp = (type_w *)d; while ((size-=sizeof(type_w)) >= 0) *wp++ = (type_w)fill_v; + break; } default: while (size-- > 0)
The -Wimplicit-fallthrough warnings help to catch bugs with forgotten "break" statements, so it's a good idea to have this switch enabled. Thus let's fix the current spots that generate warnings and add the switch to our WARNFLAGS. Signed-off-by: Thomas Huth <thuth@redhat.com> --- lib/libc/stdio/vsnprintf.c | 1 + make.rules | 4 +++- slof/prim.code | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-)