PR/35194: 0 is returned from confstr(3) in two cases:
- when an error occurred and errno is set appropriately - when the variable is undefined. Thanks to Guy Harris for pointing this out.
This commit is contained in:
parent
c74271d8ea
commit
686f9932fe
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: getconf.c,v 1.25 2006/12/06 11:05:32 mjf Exp $ */
|
||||
/* $NetBSD: getconf.c,v 1.26 2006/12/06 12:02:02 mjf Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1996, 1998 The NetBSD Foundation, Inc.
|
||||
@ -38,7 +38,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: getconf.c,v 1.25 2006/12/06 11:05:32 mjf Exp $");
|
||||
__RCSID("$NetBSD: getconf.c,v 1.26 2006/12/06 12:02:02 mjf Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <err.h>
|
||||
@ -265,16 +265,28 @@ printvar(const struct conf_variable *cp, const char *pathname)
|
||||
break;
|
||||
|
||||
case CONFSTR:
|
||||
errno = 0;
|
||||
slen = confstr((int)cp->value, NULL, 0);
|
||||
if (slen == 0)
|
||||
out: err(EXIT_FAILURE, "confstr(%ld)", cp->value);
|
||||
if (slen == 0) {
|
||||
if (errno != 0)
|
||||
|
||||
out: err(EXIT_FAILURE, "confstr(%ld)", cp->value);
|
||||
else
|
||||
print_strvar(cp->name, "undefined");
|
||||
}
|
||||
|
||||
if ((sval = malloc(slen)) == NULL)
|
||||
err(EXIT_FAILURE, "Can't allocate %zu bytes", slen);
|
||||
|
||||
if (confstr((int)cp->value, sval, slen) == 0)
|
||||
goto out;
|
||||
print_strvar(cp->name, sval);
|
||||
errno = 0;
|
||||
if (confstr((int)cp->value, sval, slen) == 0) {
|
||||
if (errno != 0)
|
||||
goto out;
|
||||
else
|
||||
print_strvar(cp->name, "undefined");
|
||||
} else
|
||||
print_strvar(cp->name, sval);
|
||||
|
||||
free(sval);
|
||||
break;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user