util: remove usage of `strerror_r` #36038

pull fanquake wants to merge 1 commits into bitcoin:master from fanquake:drop_strerror_r changing 5 files +10 −33
  1. fanquake commented at 2:27 PM on August 20, 2026: member

    Use std::system_category().message(err) on non-Windows, which internally dispatches to strerror_r, and should handle unknown errors.

    See: https://github.com/llvm/llvm-project/blob/4e9e83400a5702059c8a18e2fb6174038875e8a6/libcxx/src/system_error.cpp#L231-L237 for one standard library implementation.

  2. DrahtBot added the label Utils/log/libs on Aug 20, 2026
  3. DrahtBot commented at 2:27 PM on August 20, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process. A summary of reviews will appear here.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. fanquake force-pushed on Aug 20, 2026
  5. DrahtBot added the label CI failed on Aug 20, 2026
  6. fanquake force-pushed on Aug 20, 2026
  7. in src/util/syserror.h:11 in 1ce27d26ea
       6 | @@ -7,9 +7,8 @@
       7 |  
       8 |  #include <string>
       9 |  
      10 | -/** Return system error string from errno value. Use this instead of
      11 | - * std::strerror, which is not thread-safe. For network errors use
      12 | - * NetworkErrorString from sock.h instead.
      13 | +/** Return system error string from errno value. For network errors
      14 | + * use NetworkErrorString from sock.h instead.
    


    maflcko commented at 2:42 PM on August 20, 2026:
    /// Return system error string from errno value. For network errors
    /// use NetworkErrorString from sock.h instead.
    

    nit: The different indent looks a bit ugly? Could use a fixed-size doxygen comment?


    fanquake commented at 2:55 PM on August 20, 2026:

    Sure, changed.

  8. fanquake force-pushed on Aug 20, 2026
  9. DrahtBot removed the label CI failed on Aug 20, 2026
  10. fanquake force-pushed on Aug 21, 2026
  11. fanquake force-pushed on Sep 9, 2026
  12. fanquake force-pushed on Sep 11, 2026
  13. fanquake force-pushed on Sep 16, 2026
  14. fanquake force-pushed on Oct 2, 2026
  15. fanquake commented at 10:07 AM on October 2, 2026: member

    Dropped any Windows-specific changes here.

  16. in src/util/syserror.cpp:26 in a2b2b75f38 outdated
      22 | -    /* Too bad there are three incompatible implementations of the
      23 | -     * thread-safe strerror. */
      24 | -    const char *s = nullptr;
      25 | -#ifdef WIN32
      26 | -    if (strerror_s(buf, sizeof(buf), err) == 0) s = buf;
      27 | -#else
    


    hebasto commented at 12:20 PM on October 2, 2026:

    Is it safe to remove this Windows-specific code?


    maflcko commented at 7:58 AM on October 13, 2026:

    fanquake commented at 9:12 AM on October 19, 2026:

    Really removed any Windows related changes.

  17. fanquake force-pushed on Oct 13, 2026
  18. fanquake force-pushed on Oct 19, 2026
  19. fanquake renamed this:
    util: remove usage of `strerror_s/r`
    util: remove usage of `strerror_r`
    on Oct 19, 2026
  20. util: remove usage of strerror_r
    Use std::system_category().message(err), which internally dispatches to
    strerror_r, and should handle unknown errors.
    
    See: https://github.com/llvm/llvm-project/blob/4e9e83400a5702059c8a18e2fb6174038875e8a6/libcxx/src/system_error.cpp#L231
    cd5280d0eb
  21. fanquake force-pushed on Oct 19, 2026
  22. DrahtBot added the label CI failed on Oct 19, 2026
  23. DrahtBot commented at 9:17 AM on October 19, 2026: contributor

    <!--85328a0da195eb286784d51f73fa0af9-->

    🚧 At least one of the CI tasks failed. <sub>Task lint: https://github.com/bitcoin/bitcoin/actions/runs/39228215016/job/117979614825</sub> <sub>LLM reason (✨ experimental): CI failed because the locale-dependence lint flagged the strerror_s call in src/util/syserror.cpp.</sub>

    <details><summary>Hints</summary>

    Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example:

    • Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    • A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.

    • An intermittent issue.

    Leave a comment here, if you need help tracking down a confusing failure.

    </details>

  24. hebasto commented at 10:18 AM on October 19, 2026: member

    Use std::system_category().message(err) on non-Windows, which internally dispatches to strerror_r, and should handle unknown errors.

    See: https://github.com/llvm/llvm-project/blob/4e9e83400a5702059c8a18e2fb6174038875e8a6/libcxx/src/system_error.cpp#L231-L237 for one standard library implementation.

    In libstdc++, the corresponding change landed in https://github.com/gcc-mirror/gcc/commit/51f94778b45514992a716b0b2d7a87244e6f0018 (GCC 14) and was backported to GCC 13.3, but never to GCC 12. Does it make sense to postpone this change until #36042?

    Also

    --- a/src/util/syserror.cpp
    +++ b/src/util/syserror.cpp
    @@ -7,10 +7,12 @@
     #include <tinyformat.h>
     
     #include <string>
    -#include <system_error>
     
     #if defined(WIN32)
    +#include <cstring>
     #include <windows.h>
    +#else
    +#include <system_error>
     #endif
     
     std::string SysErrorString(int err)
    
  25. DrahtBot removed the label CI failed on Oct 19, 2026

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-10-30 09:40 UTC