rDSN icon indicating copy to clipboard operation
rDSN copied to clipboard

strerror is not thread safe.

Open linmajia opened this issue 9 years ago • 2 comments

Here is a ref implementation in file_utils.cpp:

namespace dsn{
    namespace utils {
        char *get_error_str(int errnum)
        {
            size_t sz = ARRAYSIZE(tls_path_buffer);
            auto ret =
# if defined(_WIN32)
                ::strerror_s(tls_path_buffer, sz, errnum)
# else
                ::strerror_r(errnum, str_buffer, sz)
# endif
                ;
            if (ret != 0)
            {
                snprintf_p(tls_path_buffer, sz, "Unknown system error.");
            }

            return tls_path_buffer;
        }
    }
}

linmajia avatar Dec 21 '15 07:12 linmajia

@imzhenyu, the code piece here is fine to fix the "strerror" bug, but I can't find it in our project. So is it OK if I add this to our project and change all the function calls to strerror?

shengofsun avatar Jan 11 '16 10:01 shengofsun

That will definitely help~

imzhenyu avatar Jan 11 '16 11:01 imzhenyu