ctermid: return string literal, document MT-Safety pitfall

Florian Weimer fweimer@redhat.com
Fri Nov 14 21:43:00 GMT 2014


On 11/14/2014 05:45 PM, Alexandre Oliva wrote:

> Say, given:
>
> char foo[5] = "12";
>
> int main() {
>    signal (SIGUSR1, checkme)
>    strcpy (&foo[1], "23");
> }
>
> what standard-compliant values can checkme legitimately expect to find
> in foo[0], foo[1], foo[2], foo[3], and foo[4]?

foo is not an atomic object, so this is undefined.

As a tried to explain, things turn out rather messy if you add the 
_Atomic qualifier.  I still think the values are unspecified (despite 
the standard saying they are not) because the accesses from strcpy and 
the signal handler are not sequenced.

-- 
Florian Weimer / Red Hat Product Security



More information about the Libc-alpha mailing list