+2009-04-27 Nicolas François <nicolas.francois@centraliens.net>
+
+ * libmisc/env.c: Added assertions on the snprintf results.
+
2009-04-27 Nicolas François <nicolas.francois@centraliens.net>
* NEWS, configure.in: Added configure option --enable-utmpx,
#ident "$Id$"
+#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
size_t n;
if (NULL != value) {
- newstring = xmalloc (strlen (string) + strlen (value) + 2);
- sprintf (newstring, "%s=%s", string, value);
+ size_t len = strlen (string) + strlen (value) + 2;
+ int wlen;
+ newstring = xmalloc (len);
+ wlen = snprintf (newstring, len, "%s=%s", string, value);
+ assert (wlen == (int) len -1);
} else {
newstring = xstrdup (string);
}
cp = strchr (*argv, '=');
if (NULL == cp) {
- snprintf (variable, sizeof variable, "L%d", noname++);
+ int wlen;
+ wlen = snprintf (variable, sizeof variable, "L%d", noname);
+ assert (wlen < (int) sizeof(variable));
+ noname++;
addenv (variable, *argv);
} else {
const char **p;