Is the GNU asprintf function (print highlighted line) thread safe?
(The IIC basically boils down to whether malloc thread safe.)
Consider a code example:
#define _GNU_SOURCE #include <stdio.h> #include "getValue.h" char * getValue(int key) { char * value; asprintf(&value, "%d", key); // TODO: No error handling! // If memory allocation wasn't possible, or some other error occurs, these functions will // return -1, and the contents of strp is undefined. return value; }
Here I do not touch global variables. What if my getValue is called in parallel threads? Nothing bad will happen, right?
source share