From f7b41d66a7855086fedd01d4b5f4386540eb478b Mon Sep 17 00:00:00 2001 From: weiyu Date: Mon, 15 Jul 2019 15:48:21 -0700 Subject: [PATCH] fix a bug about RaceRecord capacity --- datarace.cc | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/datarace.cc b/datarace.cc index ac86efc1..22e473f5 100644 --- a/datarace.cc +++ b/datarace.cc @@ -294,16 +294,23 @@ void fullRaceCheckRead(thread_id_t thread, const void *location, uint64_t *shado } if (copytoindex >= record->capacity) { - int newCapacity = record->capacity * 2; - thread_id_t *newthread = (thread_id_t *)snapshot_malloc(sizeof(thread_id_t) * newCapacity); - modelclock_t *newreadClock = (modelclock_t *)snapshot_malloc(sizeof(modelclock_t) * newCapacity); - std::memcpy(newthread, record->thread, record->capacity * sizeof(thread_id_t)); - std::memcpy(newreadClock, record->readClock, record->capacity * sizeof(modelclock_t)); - snapshot_free(record->readClock); - snapshot_free(record->thread); - record->readClock = newreadClock; - record->thread = newthread; - record->capacity = newCapacity; + if (record->capacity == 0) { + int newCapacity = INITCAPACITY; + record->thread = (thread_id_t *)snapshot_malloc(sizeof(thread_id_t) * newCapacity); + record->readClock = (modelclock_t *)snapshot_malloc(sizeof(modelclock_t) * newCapacity); + record->capacity = newCapacity; + } else { + int newCapacity = record->capacity * 2; + thread_id_t *newthread = (thread_id_t *)snapshot_malloc(sizeof(thread_id_t) * newCapacity); + modelclock_t *newreadClock = (modelclock_t *)snapshot_malloc(sizeof(modelclock_t) * newCapacity); + std::memcpy(newthread, record->thread, record->capacity * sizeof(thread_id_t)); + std::memcpy(newreadClock, record->readClock, record->capacity * sizeof(modelclock_t)); + snapshot_free(record->readClock); + snapshot_free(record->thread); + record->readClock = newreadClock; + record->thread = newthread; + record->capacity = newCapacity; + } } modelclock_t ourClock = currClock->getClock(thread); -- 2.34.1