Replace snprintf(NULL, 0, ...) with strlen().

snprintf(NULL, 0, ...) behavior is unconsistent and breaks on some systems.
strlen() should always work properly.