Skip to content
Commit 4f2c9703 authored by Alviro Iskandar Setiawan's avatar Alviro Iskandar Setiawan Committed by Paul E. McKenney
Browse files

tools/nolibc/stdio: Add format attribute to enable printf warnings



When we use printf and fprintf functions from the nolibc, we don't
get any warning from the compiler if we have the wrong arguments.
For example, the following calls will compile silently:
```
  printf("%s %s\n", "aaa");
  fprintf(stdout, "%s %s\n", "xxx", 1);
```
(Note the wrong arguments).

Those calls are undefined behavior. The compiler can help us warn
about the above mistakes by adding a `printf` format attribute to
those functions declaration. This patch adds it, and now it yields
these warnings for those mistakes:
```
  warning: format `%s` expects a matching `char *` argument [-Wformat=]
  warning: format `%s` expects argument of type `char *`, but argument 4 has type `int` [-Wformat=]
```

  [ ammarfaizi2: Simplify the attribute placement. ]

Signed-off-by: default avatarAlviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org>
Signed-off-by: default avatarAmmar Faizi <ammarfaizi2@gnuweeb.org>
Acked-by: default avatarWilly Tarreau <w@1wt.eu>
Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
parent 1ef150cf
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment