visual c++ - SAL annotations and new operator overload -


i have problem sal annotations , new operator overloading. want provide new operator not throws exceptions return nullptr in case of error. have written:

_check_return_ _ret_maybenull_ _success_(return != nullptr) void* operator new(_in_ size_t size) {     return malloc(size); } 

unfortunately vs2012 see declaration of new provided in <new> header different , after build->run code analysis gives me lot of errors declarations incompatible. chooses declaration provided in <new> indicates new never returns null. have tried remove <new> include not (it included different headers <vector>). how can convince compiler use sal annotations?

can't link nothrownew.obj, if non-throwing new want?

be aware though it's bad idea. 1 thing, stl implementation shipped msvc doesn't expect new return null , doesn't check that, goes right ahead , uses pointer. if use stl, , if run out of memory, instead of bad_alloc exception you'll access violation - hardly improvement.


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -