Repository: bitcoin/bitcoin (language: cpp)

Issue:
depends bdb -Werror=format-security "format not a string literal and no format arguments"
Running `make -C depends` on nixos with gcc 10.3.0 results in

```c++
libtool: compile:  gcc -c -I. -I../dist/./.. -I/home/russ/work/bitcoin/depends/x86_64-pc-linux-gnu/include -D_GNU_SOURCE -D_REENTRANT -pipe -O2 -Wno-error=implicit-function-declaration ../dist/./../txn/txn.c  -fPIC -DPIC -o txn.o
../dist/./../txn/txn.c: In function ‘__txn_begin’:
../dist/./../txn/txn.c:171:3: error: format not a string literal and no format arguments [-Werror=format-security]
  171 |   __db_errx(env, TxnAlloc);
      |   ^~~~~~~~~
../dist/./../txn/txn.c: In function ‘__txn_compensate_begin’:
../dist/./../txn/txn.c:318:3: error: format not a string literal and no format arguments [-Werror=format-security]
  318 |   __db_errx(env, TxnAlloc);
      |   ^~~~~~~~~
cc1: some warnings being treated as errors
make[1]: *** [Makefile:1980: txn.o] Error 1
make[1]: Leaving directory '/home/russ/work/bitcoin/depends/work/build/x86_64-pc-linux-gnu/bdb/4.8.30-1205703c56a/build_unix'
make: *** [funcs.mk:288: /home/russ/work/bitcoin/depends/work/build/x86_64-pc-linux-gnu/bdb/4.8.30-1205703c56a/build_unix/.stamp_built] Error 2
make: Leaving directory '/home/russ/work/bitcoin/depends'
```

I could work around it with

```diff
diff --git a/depends/packages/bdb.mk b/depends/packages/bdb.mk
index dc536fd3991..b69276cb154 100644
--- a/depends/packages/bdb.mk
+++ b/depends/packages/bdb.mk
@@ -14,7 +14,7 @@ $(package)_config_opts_freebsd=--with-pic
 $(package)_config_opts_netbsd=--with-pic
 $(package)_config_opts_openbsd=--with-pic
 $(package)_config_opts_android=--with-pic
-$(package)_cflags+=-Wno-error=implicit-function-declaration
+$(package)_cflags+=-Wno-error=implicit-function-declaration -Wno-error=format-security
 $(package)_cxxflags+=-std=c++17
 $(package)_cppflags_mingw32=-DUNICODE -D_UNICODE
 endef

```

But I don't know if this is the right fix or if there possibly is a real bug in the code causing the warning.


Discussion / hints:
What is adding `-Werror` in the first place?

Edit: Oh, BerkeleyDB's build system does?

FWIW, for zeromq we explicitly disable Werror, maybe it makes sense here too:
```
depends/packages/zeromq.mk:  $(package)_config_opts += --disable-Werror --disable-drafts --enable-option-checking
```
I think in general it is good to disable Werror for any kind of external packaging. Internally, since we do care very much about dependencies though, it maybe be good to let some warnings trigger errors, particularly security warnings like this one.

In this case it's probably worth looking into the warning to see if it's real. I believe this warning is about printing a c string with `printf(c_str)` instead of `printf("%s", c_str)`, which can be a bad thing to do.



Fix patch:
diff --git a/depends/packages/bdb.mk b/depends/packages/bdb.mk
index dc536fd3991e7..62c462620bb2a 100644
--- a/depends/packages/bdb.mk
+++ b/depends/packages/bdb.mk
@@ -14,7 +14,7 @@ $(package)_config_opts_freebsd=--with-pic
 $(package)_config_opts_netbsd=--with-pic
 $(package)_config_opts_openbsd=--with-pic
 $(package)_config_opts_android=--with-pic
-$(package)_cflags+=-Wno-error=implicit-function-declaration
+$(package)_cflags+=-Wno-error=implicit-function-declaration -Wno-error=format-security -Wno-error=implicit-int
 $(package)_cxxflags+=-std=c++17
 $(package)_cppflags_mingw32=-DUNICODE -D_UNICODE
 endef
diff --git a/depends/packages/libxkbcommon.mk b/depends/packages/libxkbcommon.mk
index 8c6c56545f075..bcdcf671f71ad 100644
--- a/depends/packages/libxkbcommon.mk
+++ b/depends/packages/libxkbcommon.mk
@@ -5,9 +5,14 @@ $(package)_file_name=$(package)-$($(package)_version).tar.xz
 $(package)_sha256_hash=60ddcff932b7fd352752d51a5c4f04f3d0403230a584df9a2e0d5ed87c486c8b
 $(package)_dependencies=libxcb
 
+# This package explicitly enables -Werror=array-bounds, which causes build failures
+# with GCC 12.1+. Work around that by turning errors back into warnings.
+# This workaround would be dropped if the package was updated, as that would require
+# a different build system (Meson)
 define $(package)_set_vars
 $(package)_config_opts = --enable-option-checking --disable-dependency-tracking
 $(package)_config_opts += --disable-static --disable-docs
+$(package)_cflags += -Wno-error=array-bounds
 endef
 
 define $(package)_preprocess_cmds


Test patch: