AnsweredAssumed Answered

toupper is not thread safe.

Question asked by Steve_E_B on Dec 11, 2014
Latest reply on Jan 7, 2015 by MurrayA

Not sure where to post this. I'll post here because I found it using TS201.

 

Recently discovered that the functions toupper, tolower defined in ctype.h are not thread safe (not re-entrant). For some reason the functions use a global variable for temporary storage.

I only use this function to parse a parameter string when opening a device driver

Sure enough, if a race condition exists, it will happen.

 

Solved easily enough by using my own function:

char toupper(char c) { return (c < 'a') || (c > 'z') ? c : c & ~0x20; }

Outcomes