char buffer[1024];
int written = vsnprintf(buffer, sizeof(buffer), format, ap);
+ if (written < 0) {
+ return; /* shouldn't happen */
/* Overflow. */
- if ((size_t)written >= sizeof(buffer)) {
+ } else if ((size_t)written >= sizeof(buffer)) {
written = sizeof(buffer) - 1;
}
assert(fd >= 0);
int length = snprintf(x, 10 + 1, "%d", fd);
- if (length >= 10 + 1) {
+ if (length >= 10 + 1 || length <= 0 /* shouldn't happen */) {
/* Integer too big to fit the buffer, skip it. */
#ifdef WARNING
warning("update_environment_buffer_entry(): truncated fd: %d [%d]\n",