https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110133

            Bug ID: 110133
           Summary: System error message should ideally use strerror_r
                    over strerror
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: romain.geissler at amadeus dot com
  Target Milestone: ---

Hi,

Checking the source code, it seems that the underlying implementation of
generic_category/system_category message() function uses this code:

    return string(strerror(i));

which happens to be thread safe when targetting glibc, but that remains an
implementation details, and not necessarily all libc implement this behavior.
Ideally strerror_r shall be used when available.

Note that unfortunately, glibc has two strerror_r implementations, with a
different return type and thus a different behavior. As an example to cope with
both behavior libc++ choose to use this overloading mechanism:
https://github.com/llvm/llvm-project/blob/2bd82c5462d511f1e58e7d9a4dcd5628cd16a32d/libcxx/src/system_error.cpp#LL114C8-L114C21

In the gcc project, the maintainers of libgfortran have implemented a similar
change this way:
https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=723553bdc16695ecc686a2ffdff6d15bd600b676;hp=62f9aedcd0a97001f290a1c13fa66efd207a23cc

Reply via email to