We can use this instead of casting the result of size_t to int. Also change checks for snprintf() returning <=0 to <0.