Skip to content

test: format-truncation warning in dbwrapper_tests #27014

@Sjors

Description

@Sjors

Compiling master at e1bf547 on Ubuntu 22.10 (with depends):

  CXX      test/test_bitcoin-dbwrapper_tests.o
test/dbwrapper_tests.cpp: In member function ‘void dbwrapper_tests::iterator_string_ordering::test_method()’:
test/dbwrapper_tests.cpp:365:41: error: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size 10 [-Werror=format-truncation=]
  365 |             snprintf(buf, sizeof(buf), "%d", x);
      |                                         ^~
test/dbwrapper_tests.cpp:365:40: note: directive argument in the range [-2147483648, 9]
  365 |             snprintf(buf, sizeof(buf), "%d", x);
      |                                        ^~~~
In file included from /usr/include/stdio.h:906,
                 from /usr/include/c++/12/cstdio:42,
                 from /usr/include/c++/12/ext/string_conversions.h:43,
                 from /usr/include/c++/12/bits/basic_string.h:3960,
                 from /usr/include/c++/12/string:53,
                 from ./clientversion.h:30,
                 from ./dbwrapper.h:8,
                 from test/dbwrapper_tests.cpp:5:
In function ‘int snprintf(char*, size_t, const char*, ...)’,
    inlined from ‘void dbwrapper_tests::iterator_string_ordering::test_method()’ at test/dbwrapper_tests.cpp:365:21:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:54:35: note: ‘__builtin___snprintf_chk’ output between 2 and 12 bytes into a destination of size 10
   54 |   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   55 |                                    __glibc_objsize (__s), __fmt,
      |                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   56 |                                    __va_arg_pack ());
      |                                    ~~~~~~~~~~~~~~~~~

(I ran with --enable-werror, otherwise it's merely a warning)

cc @achow101

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions