* libmisc/env.c: Added assertions on the snprintf results.
This commit is contained in:
parent
80fd2969c9
commit
988f7334ad
@ -1,3 +1,7 @@
|
|||||||
|
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>
|
2009-04-27 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
* NEWS, configure.in: Added configure option --enable-utmpx,
|
* NEWS, configure.in: Added configure option --enable-utmpx,
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
#ident "$Id$"
|
#ident "$Id$"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -92,8 +93,11 @@ void addenv (const char *string, /*@null@*/const char *value)
|
|||||||
size_t n;
|
size_t n;
|
||||||
|
|
||||||
if (NULL != value) {
|
if (NULL != value) {
|
||||||
newstring = xmalloc (strlen (string) + strlen (value) + 2);
|
size_t len = strlen (string) + strlen (value) + 2;
|
||||||
sprintf (newstring, "%s=%s", string, value);
|
int wlen;
|
||||||
|
newstring = xmalloc (len);
|
||||||
|
wlen = snprintf (newstring, len, "%s=%s", string, value);
|
||||||
|
assert (wlen == (int) len -1);
|
||||||
} else {
|
} else {
|
||||||
newstring = xstrdup (string);
|
newstring = xstrdup (string);
|
||||||
}
|
}
|
||||||
@ -187,7 +191,10 @@ void set_env (int argc, char *const *argv)
|
|||||||
|
|
||||||
cp = strchr (*argv, '=');
|
cp = strchr (*argv, '=');
|
||||||
if (NULL == cp) {
|
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);
|
addenv (variable, *argv);
|
||||||
} else {
|
} else {
|
||||||
const char **p;
|
const char **p;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user