bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: strerror vs. threads [was: new files imported without new modules ad


From: Simon Josefsson
Subject: Re: strerror vs. threads [was: new files imported without new modules added]
Date: Tue, 24 May 2011 20:52:31 +0200
User-agent: Gnus/5.110018 (No Gnus v0.18) Emacs/23.2 (gnu/linux)

Eric Blake <address@hidden> writes:

> On 05/24/2011 12:06 PM, Sam Steingold wrote:
>>> * Eric Blake <address@hidden> [2011-05-24 10:54:20 -0600]:
>>>
>>> Are you multi-threaded?  Then you are suffering from a data race.
>> 
>> I am sorry, I am afraid I am out of my depth.
>> Why is this function "suffering from a data race"?
>> 
>> const char *strerror (int e) {
>>   switch (e) {
>>     case EINPROGRESS: return "Operation now in progress";
>>     case EALREADY: return "Operation already in progress";
>>     ...
>>   }
> ...
>   {
>     static char const fmt[] = "Unknown error (%d)";
>     verify (sizeof (buf) >= sizeof (fmt) + INT_STRLEN_BOUND (n));
>     sprintf (buf, fmt, n);
>
>> }
>
> Try:
>
> strerror(-1) in thread 1
> strerror(-2) in thread 2
>
> POSIX explicitly allows strerror to use a static buffer, and that's
> _exactly_ what gnulib's implementation does on out-of-range input.
> Which means that "Unknown error (-1)" of thread 1 and "Unknown error
> (-2)" of thread 2 are calling sprintf on the same memory at the same
> time, and you will get indeterminate results.

Which begs the question why the error messages needs to be different for
different unknown errors?  Is that required by POSIX?

/Simon



reply via email to

[Prev in Thread] Current Thread [Next in Thread]