I'm working on a multithreaded project which suffered from a number of bugs due to use of the library function "strtok()" which is not thread-safe.
I'd love to find a way to forbid use of this function (and perhaps others) by defining something in the project file (Qt Creator / qmake) (e.g. redefining the symbol), to keep new developers or seasoned bugmakers from introducing it again.
Any ideas?
this is what the GCC manual says about elimination of the use of certain library functions:
#pragma GCC poison
Sometimes, there is an identifier that you want to remove completely
from your program, and make sure that it never creeps back in.
To enforce this, you can poison the identifier with this pragma.
#pragma GCC poison is followed by a list of identifiers to poison.
If any of those identifiers appears anywhere in the source after the directive,
it is a hard error. For example,
#pragma GCC poison printf sprintf fprintf
sprintf(some_string, "hello");
will produce an error.
If a poisoned identifier appears
as part of the expansion of a macro which was defined
before the identifier was poisoned, it will not cause an error.
This lets you poison an identifier
without worrying about system headers defining macros that use it.
For example,
#define strrchr rindex
#pragma GCC poison rindex
strrchr(some_string, 'h');
will not produce an error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With