Surface::create already initialized memory to 0 and getPixels can be nullptr if bitmap size is 0. In this case memset gets called with nullptr which is undefined behaviour.