Eric Blake <ebl...@redhat.com> writes: > On 05/24/2011 12:06 PM, Sam Steingold wrote: >>> * Eric Blake <roy...@erqung.pbz> [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