Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libnvmm Fix error handling of realloc, and use memmove b...
details: https://anonhg.NetBSD.org/src/rev/aad0f6e77cd2
branches: trunk
changeset: 446000:aad0f6e77cd2
user: maxv <maxv%NetBSD.org@localhost>
date: Mon Nov 19 21:45:37 2018 +0000
description:
Fix error handling of realloc, and use memmove because the areas overlap;
noted by agc@. These _nvmm_area_add/delete functions don't make a lot of
sense right now and will likely be rewritten to match the behavior
expected by Qemu; but still fix for the time being.
Also fix a collision check while here.
diffstat:
lib/libnvmm/libnvmm.c | 14 +++++++-------
1 files changed, 7 insertions(+), 7 deletions(-)
diffs (46 lines):
diff -r 849022750ae1 -r aad0f6e77cd2 lib/libnvmm/libnvmm.c
--- a/lib/libnvmm/libnvmm.c Mon Nov 19 20:44:51 2018 +0000
+++ b/lib/libnvmm/libnvmm.c Mon Nov 19 21:45:37 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: libnvmm.c,v 1.1 2018/11/10 09:28:56 maxv Exp $ */
+/* $NetBSD: libnvmm.c,v 1.2 2018/11/19 21:45:37 maxv Exp $ */
/*
* Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -60,8 +60,8 @@
gpa < mach->areas[i].gpa + mach->areas[i].size) {
goto error;
}
- if (gpa + size >= mach->areas[i].gpa &&
- gpa + size < mach->areas[i].gpa + mach->areas[i].size) {
+ if (gpa + size > mach->areas[i].gpa &&
+ gpa + size <= mach->areas[i].gpa + mach->areas[i].size) {
goto error;
}
if (gpa < mach->areas[i].gpa &&
@@ -70,13 +70,13 @@
}
}
- mach->nareas++;
- ptr = realloc(mach->areas, mach->nareas * sizeof(struct nvmm_area));
+ ptr = realloc(mach->areas, (mach->nareas + 1) *
+ sizeof(struct nvmm_area));
if (ptr == NULL)
return -1;
mach->areas = ptr;
- area = &mach->areas[mach->nareas-1];
+ area = &mach->areas[mach->nareas++];
area->gpa = gpa;
area->hva = hva;
area->size = size;
@@ -106,7 +106,7 @@
return -1;
}
- memcpy(&mach->areas[i], &mach->areas[i+1],
+ memmove(&mach->areas[i], &mach->areas[i+1],
(mach->nareas - i - 1) * sizeof(struct nvmm_area));
mach->nareas--;
Home |
Main Index |
Thread Index |
Old Index