Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strerror_r requires non-null buffer pointer #122

Merged
merged 2 commits into from
Jun 3, 2024

Conversation

ashtum
Copy link
Contributor

@ashtum ashtum commented Jun 2, 2024

According to the documentation, in the non-allocating overload of message, we can pass a nullptr for buffer when len is 0.

If len is 0, nothing is copied, but the function still returns buffer. Note that when len is 0, buffer may be nullptr

Compiling the following generates -Wnonnull warnings, because buffer parameter in strerror_r signature is marked as non-null:
https://godbolt.org/z/sdbvfY7vo

#include <boost/system.hpp>

int main()
{
  boost::system::error_code ec;
  ec.message(nullptr, 0);
}
In file included from /opt/compiler-explorer/libs/boost_1_84_0/boost/system/detail/generic_category.hpp:14,
                 from /opt/compiler-explorer/libs/boost_1_84_0/boost/system/detail/error_condition.hpp:14,
                 from /opt/compiler-explorer/libs/boost_1_84_0/boost/system/detail/error_code.hpp:15,
                 from /opt/compiler-explorer/libs/boost_1_84_0/boost/system/error_code.hpp:13,
                 from /opt/compiler-explorer/libs/boost_1_84_0/boost/system.hpp:10,
                 from <source>:1:
In function 'const char* boost::system::detail::generic_error_category_message(int, char*, std::size_t)',
    inlined from 'const char* boost::system::detail::system_error_category_message(int, char*, std::size_t)' at /opt/compiler-explorer/libs/boost_1_84_0/boost/system/detail/system_category_message.hpp:62:42,
    inlined from 'const char* boost::system::error_code::message(char*, std::size_t) const' at /opt/compiler-explorer/libs/boost_1_84_0/boost/system/detail/error_code.hpp:311:57,
    inlined from 'int main()' at <source>:6:13:
/opt/compiler-explorer/libs/boost_1_84_0/boost/system/detail/generic_category_message.hpp:42:41: warning: argument 2 null where non-null expected [-Wnonnull]
   42 |     return strerror_r_helper( strerror_r( ev, buffer, len ), buffer );
      |                               ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
In file included from /opt/compiler-explorer/gcc-13.3.0/include/c++/13.3.0/cstring:42,
                 from /opt/compiler-explorer/libs/boost_1_84_0/boost/system/detail/generic_category_message.hpp:15:
/usr/include/string.h: In function 'int main()':
/usr/include/string.h:444:14: note: in a call to function 'char* strerror_r(int, char*, size_t)' declared 'nonnull'
  444 | extern char *strerror_r (int __errnum, char *__buf, size_t __buflen)
      |              ^~~~~~~~~~
Compiler returned: 0

@ashtum
Copy link
Contributor Author

ashtum commented Jun 2, 2024

https://github.com/boostorg/system/actions/runs/9338190106/job/25703151871?pr=122#step:4:3

  sudo apt-get update
  sudo apt-get -y install g++-11
  shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
  env:
    UBSAN_OPTIONS: print_stacktrace=1
Get:1 file:/etc/apt/apt-mirrors.txt Mirrorlist [142 B]
Hit:2 http://azure.archive.ubuntu.com/ubuntu focal InRelease
Hit:6 https://packages.microsoft.com/repos/azure-cli focal InRelease
Get:3 http://azure.archive.ubuntu.com/ubuntu focal-updates InRelease [128 kB]
Get:4 http://azure.archive.ubuntu.com/ubuntu focal-backports InRelease [128 kB]
Get:5 http://azure.archive.ubuntu.com/ubuntu focal-security InRelease [128 kB]
Get:7 https://packages.microsoft.com/ubuntu/20.04/prod focal InRelease [3632 B]
Get:8 http://azure.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [3332 kB]
Get:9 http://azure.archive.ubuntu.com/ubuntu focal-updates/main Translation-en [525 kB]
Get:10 http://azure.archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [1189 kB]
Get:11 http://azure.archive.ubuntu.com/ubuntu focal-updates/universe Translation-en [285 kB]
Get:12 http://azure.archive.ubuntu.com/ubuntu focal-security/main amd64 Packages [2956 kB]
Get:13 http://azure.archive.ubuntu.com/ubuntu focal-security/main Translation-en [444 kB]
Get:14 http://azure.archive.ubuntu.com/ubuntu focal-security/universe amd64 Packages [963 kB]
Get:15 http://azure.archive.ubuntu.com/ubuntu focal-security/universe Translation-en [203 kB]
Get:16 https://packages.microsoft.com/ubuntu/20.04/prod focal/main arm64 Packages [60.6 kB]
Get:17 https://packages.microsoft.com/ubuntu/20.04/prod focal/main amd64 Packages [293 kB]
Fetched 10.6 MB in 1s (7192 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
Reading state information...
clang-11 is already the newest version (1:11.0.0-2~ubuntu20.04.1).
The following additional packages will be installed:
  fonts-mathjax libjs-mathjax
Suggested packages:
  fonts-mathjax-extras fonts-stix libjs-mathjax-doc
The following NEW packages will be installed:
  clang-11-doc clang-11-examples fonts-mathjax libclang-11-dev libjs-mathjax
  python3-clang-11

This doesn't make any sense, why it tries to install clang-11!

@pdimov
Copy link
Member

pdimov commented Jun 2, 2024

I'll take care of it.

@pdimov
Copy link
Member

pdimov commented Jun 2, 2024

Can you please make the following changes:

  • rebase on develop to pick up the new ci.yml
  • remove the changes to generic_category_test and system_category_test
  • remove the inclusion of core/ignore_unused.hpp and the uses of boost::ignore_unused

Thanks.

ashtum added 2 commits June 2, 2024 18:20
Fixes -Wnonnull warnings when calling message with a nullptr buffer
@ashtum ashtum force-pushed the message-nonnull-warnings branch from 336efa1 to 4d4f906 Compare June 2, 2024 18:22
@pdimov pdimov merged commit 4d4f906 into boostorg:develop Jun 3, 2024
116 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants