Add NULL handling in C++ code