https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124183 --- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Adding: if (!cstr) { return 1; } After the malloc does fix the warning.