realloc doesn't guarantee zeroing...
[model-checker.git] / clockvector.cc
index 062ac4148e6573a4f00f59ccd6b947c5d37259e7..4dd03dc26fb7291a59ed4d1304358948bff6e062 100644 (file)
@@ -40,27 +40,19 @@ ClockVector::~ClockVector()
  */
 void ClockVector::merge(const ClockVector *cv)
 {
-       modelclock_t *clk = clock;
-       bool resize = false;
-
        ASSERT(cv != NULL);
 
        if (cv->num_threads > num_threads) {
-               resize = true;
-               clk = (modelclock_t *)snapshot_malloc(cv->num_threads * sizeof(modelclock_t));
+               clock = (modelclock_t *)snapshot_realloc(clock, cv->num_threads * sizeof(modelclock_t));
+               for (int i= num_threads; i < cv->num_threads; i++)
+                       clock[i] = 0;
+               num_threads = cv->num_threads;
        }
 
        /* Element-wise maximum */
-       for (int i = 0; i < num_threads; i++)
-               clk[i] = std::max(clock[i], cv->clock[i]);
-
-       if (resize) {
-               for (int i = num_threads; i < cv->num_threads; i++)
-                       clk[i] = cv->clock[i];
-               num_threads = cv->num_threads;
-               snapshot_free(clock);
-       }
-       clock = clk;
+       for (int i = 0; i < cv->num_threads; i++)
+               if (cv->clock[i] > clock[i])
+                       clock[i] = cv->clock[i];
 }
 
 /**