Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern gcc silently optimizes away a != NULL check if a po...
details: https://anonhg.NetBSD.org/src/rev/8f1031c18363
branches: trunk
changeset: 344113:8f1031c18363
user: mlelstv <mlelstv%NetBSD.org@localhost>
date: Sun Mar 13 10:07:22 2016 +0000
description:
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.
diffstat:
sys/kern/subr_autoconf.c | 15 +++++++++------
1 files changed, 9 insertions(+), 6 deletions(-)
diffs (50 lines):
diff -r 8c60caa95660 -r 8f1031c18363 sys/kern/subr_autoconf.c
--- a/sys/kern/subr_autoconf.c Sun Mar 13 09:12:16 2016 +0000
+++ b/sys/kern/subr_autoconf.c Sun Mar 13 10:07:22 2016 +0000
@@ -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 @@
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 @@
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;
Home |
Main Index |
Thread Index |
Old Index