Module Name: src Committed By: mlelstv Date: Sun Mar 13 10:07:22 UTC 2016
Modified Files: src/sys/kern: subr_autoconf.c Log Message: gcc silently optimizes away a != NULL check if a pointer has been used before. - assert that old size == 0 or old pointer valid - check for size instead - rewrite array splice operation with simple loops instead of memcpy/memset. To generate a diff of this commit: cvs rdiff -u -r1.239 -r1.240 src/sys/kern/subr_autoconf.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/subr_autoconf.c diff -u src/sys/kern/subr_autoconf.c:1.239 src/sys/kern/subr_autoconf.c:1.240 --- src/sys/kern/subr_autoconf.c:1.239 Thu Jan 28 16:32:40 2016 +++ src/sys/kern/subr_autoconf.c Sun Mar 13 10:07:22 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_autoconf.c,v 1.239 2016/01/28 16:32:40 christos Exp $ */ +/* $NetBSD: subr_autoconf.c,v 1.240 2016/03/13 10:07:22 mlelstv Exp $ */ /* * Copyright (c) 1996, 2000 Christopher G. Demetriou @@ -77,7 +77,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.239 2016/01/28 16:32:40 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.240 2016/03/13 10:07:22 mlelstv Exp $"); #ifdef _KERNEL_OPT #include "opt_ddb.h" @@ -2649,6 +2649,8 @@ device_active_register(device_t dev, voi old_handlers = dev->dv_activity_handlers; old_size = dev->dv_activity_count; + KASSERT(old_size == 0 || old_handlers != NULL); + for (i = 0; i < old_size; ++i) { KASSERT(old_handlers[i] != handler); if (old_handlers[i] == NULL) { @@ -2660,17 +2662,18 @@ device_active_register(device_t dev, voi new_size = old_size + 4; new_handlers = kmem_alloc(sizeof(void *[new_size]), KM_SLEEP); - memcpy(new_handlers, old_handlers, sizeof(void *[old_size])); + for (i = 0; i < old_size; ++i) + new_handlers[i] = old_handlers[i]; new_handlers[old_size] = handler; - memset(new_handlers + old_size + 1, 0, - sizeof(int [new_size - (old_size+1)])); + for (i = old_size+1; i < new_size; ++i) + new_handlers[i] = NULL; s = splhigh(); dev->dv_activity_count = new_size; dev->dv_activity_handlers = new_handlers; splx(s); - if (old_handlers != NULL) + if (old_size > 0) kmem_free(old_handlers, sizeof(void * [old_size])); return true;