From: weiyu Date: Mon, 15 Jul 2019 22:48:21 +0000 (-0700) Subject: fix a bug about RaceRecord capacity X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=f7b41d66a7855086fedd01d4b5f4386540eb478b;p=c11tester.git fix a bug about RaceRecord capacity --- 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);