]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fixed wrong size in pthread struct transfer
authorYann Collet <cyan@fb.com>
Wed, 20 Jun 2018 03:14:03 +0000 (20:14 -0700)
committerYann Collet <cyan@fb.com>
Wed, 20 Jun 2018 03:14:03 +0000 (20:14 -0700)
lib/common/pool.c
tests/zstreamtest.c

index a0e2bedf0433a437e528d7931d4d36ea5788464d..7f9219e36df569c46014e7b1e406edc0a9b47081 100644 (file)
@@ -196,19 +196,18 @@ static POOL_ctx* POOL_resize_internal(POOL_ctx* ctx, size_t numThreads)
     {   ZSTD_pthread_t* const threadPool = (ZSTD_pthread_t*)ZSTD_malloc(numThreads * sizeof(ZSTD_pthread_t), ctx->customMem);
         if (!threadPool) return NULL;
         /* replace existing thread pool */
-        memcpy(threadPool, ctx->threads, ctx->threadCapacity);
+        memcpy(threadPool, ctx->threads, ctx->threadCapacity * sizeof(ctx->threads[0]));
         ZSTD_free(ctx->threads, ctx->customMem);
         ctx->threads = threadPool;
         /* Initialize additional threads */
         {   size_t threadId;
             for (threadId = ctx->threadCapacity; threadId < numThreads; ++threadId) {
                 if (ZSTD_pthread_create(&threadPool[threadId], NULL, &POOL_thread, ctx)) {
-                    break;
+                    ctx->threadCapacity = threadId;
+                    ctx->threadLimit = threadId;
+                    return NULL;   /* will release the pool */
             }   }
-            if (threadId != numThreads) {  /* not all threads successfully init */
-                ctx->threadCapacity = threadId;
-                return NULL;   /* will release the pool */
-    }   }   }
+    }   }
     /* successfully expanded */
     ctx->threadCapacity = numThreads;
     ctx->threadLimit = numThreads;
index 425fbab39f03164cd90a137f9d21b3691dbcd622..fba99aa34b8f5db61536afc440687919d99cd289 100644 (file)
@@ -1643,13 +1643,13 @@ static int fuzzerTests_newAPI(U32 seed, U32 nbTests, unsigned startTest, double
             DISPLAYLEVEL(5, "Creating new context \n");
             ZSTD_freeCCtx(zc);
             zc = ZSTD_createCCtx();
-            CHECK(zc==NULL, "ZSTD_createCCtx allocation error");
-            resetAllowed=0;
+            CHECK(zc == NULL, "ZSTD_createCCtx allocation error");
+            resetAllowed = 0;
         }
         if ((FUZ_rand(&lseed) & 0xFF) == 132) {
             ZSTD_freeDStream(zd);
             zd = ZSTD_createDStream();
-            CHECK(zd==NULL, "ZSTD_createDStream allocation error");
+            CHECK(zd == NULL, "ZSTD_createDStream allocation error");
             ZSTD_initDStream_usingDict(zd, NULL, 0);  /* ensure at least one init */
         }