svn commit: r325372 - stable/11/sys/contrib/libnv
Jilles Tjoelker
jilles at FreeBSD.org
Fri Nov 3 22:41:33 UTC 2017
Author: jilles
Date: Fri Nov 3 22:41:31 2017
New Revision: 325372
URL: https://svnweb.freebsd.org/changeset/base/325372
Log:
MFC r325017: libnv: Fix strict-aliasing violation with cookie
In r323851 (MFC'ed to stable/11 as r324831), some casts were adjusted in
calls to nvlist_next() and nvlist_get_pararr() in order to make scan-build
happy. I think these changes just confused scan-build into not reporting
the strict-aliasing violation.
For example, nvlist_xdescriptors() is causing nvlist_next() to write to its
local variable nvp of type nvpair_t * using the lvalue *cookiep of type
void *, which is not allowed. Given the APIs of nvlist_next(),
nvlist_get_parent() and nvlist_get_pararr(), one possible fix is to create a
local void *cookie in nvlist_xdescriptors() and other places, and to convert
the value to nvpair_t * when necessary. This patch implements that fix.
Modified:
stable/11/sys/contrib/libnv/nvlist.c
Directory Properties:
stable/11/ (props changed)
Modified: stable/11/sys/contrib/libnv/nvlist.c
==============================================================================
--- stable/11/sys/contrib/libnv/nvlist.c Fri Nov 3 21:04:22 2017 (r325371)
+++ stable/11/sys/contrib/libnv/nvlist.c Fri Nov 3 22:41:31 2017 (r325372)
@@ -708,15 +708,17 @@ out:
static int *
nvlist_xdescriptors(const nvlist_t *nvl, int *descs)
{
+ void *cookie;
nvpair_t *nvp;
int type;
NVLIST_ASSERT(nvl);
PJDLOG_ASSERT(nvl->nvl_error == 0);
- nvp = NULL;
+ cookie = NULL;
do {
- while (nvlist_next(nvl, &type, (void *)&nvp) != NULL) {
+ while (nvlist_next(nvl, &type, &cookie) != NULL) {
+ nvp = cookie;
switch (type) {
case NV_TYPE_DESCRIPTOR:
*descs = nvpair_get_descriptor(nvp);
@@ -738,7 +740,7 @@ nvlist_xdescriptors(const nvlist_t *nvl, int *descs)
}
case NV_TYPE_NVLIST:
nvl = nvpair_get_nvlist(nvp);
- nvp = NULL;
+ cookie = NULL;
break;
case NV_TYPE_NVLIST_ARRAY:
{
@@ -750,12 +752,12 @@ nvlist_xdescriptors(const nvlist_t *nvl, int *descs)
PJDLOG_ASSERT(nitems > 0);
nvl = value[0];
- nvp = NULL;
+ cookie = NULL;
break;
}
}
}
- } while ((nvl = nvlist_get_pararr(nvl, (void *)&nvp)) != NULL);
+ } while ((nvl = nvlist_get_pararr(nvl, &cookie)) != NULL);
return (descs);
}
@@ -785,6 +787,7 @@ size_t
nvlist_ndescriptors(const nvlist_t *nvl)
{
#ifndef _KERNEL
+ void *cookie;
nvpair_t *nvp;
size_t ndescs;
int type;
@@ -793,16 +796,17 @@ nvlist_ndescriptors(const nvlist_t *nvl)
PJDLOG_ASSERT(nvl->nvl_error == 0);
ndescs = 0;
- nvp = NULL;
+ cookie = NULL;
do {
- while (nvlist_next(nvl, &type, (void *)&nvp) != NULL) {
+ while (nvlist_next(nvl, &type, &cookie) != NULL) {
+ nvp = cookie;
switch (type) {
case NV_TYPE_DESCRIPTOR:
ndescs++;
break;
case NV_TYPE_NVLIST:
nvl = nvpair_get_nvlist(nvp);
- nvp = NULL;
+ cookie = NULL;
break;
case NV_TYPE_NVLIST_ARRAY:
{
@@ -814,7 +818,7 @@ nvlist_ndescriptors(const nvlist_t *nvl)
PJDLOG_ASSERT(nitems > 0);
nvl = value[0];
- nvp = NULL;
+ cookie = NULL;
break;
}
case NV_TYPE_DESCRIPTOR_ARRAY:
@@ -828,7 +832,7 @@ nvlist_ndescriptors(const nvlist_t *nvl)
}
}
}
- } while ((nvl = nvlist_get_pararr(nvl, (void *)&nvp)) != NULL);
+ } while ((nvl = nvlist_get_pararr(nvl, &cookie)) != NULL);
return (ndescs);
#else
More information about the svn-src-stable-11
mailing list