Skip to content

Commit b2ca647

Browse files
authored
Merge pull request #6476 from n8sh/zip-zlib-uninitializedArray
[Trivial] zip & zlib: don't zero-fill buffers before writing to them merged-on-behalf-of: Vladimir Panteleev <github@thecybershadow.net>
2 parents 832ace0 + 8ae499e commit b2ca647

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

std/zip.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ final class ZipArchive
414414
*/
415415
void[] build() @safe pure
416416
{
417-
import std.array : array;
417+
import std.array : array, uninitializedArray;
418418
import std.algorithm.sorting : sort;
419419
import std.string : representation;
420420

@@ -449,7 +449,7 @@ final class ZipArchive
449449
if (isZip64)
450450
dataSize += eocd64LocLength + eocd64Length;
451451

452-
_data = new ubyte[dataSize];
452+
_data = uninitializedArray!(ubyte[])(dataSize);
453453

454454
// Populate the data[]
455455

std/zlib.d

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,9 @@ in
201201
do
202202
{
203203
import core.memory : GC;
204+
import std.array : uninitializedArray;
204205
auto destlen = srcbuf.length + ((srcbuf.length + 1023) / 1024) + 12;
205-
auto destbuf = new ubyte[destlen];
206+
auto destbuf = uninitializedArray!(ubyte[])(destlen);
206207
auto err = etc.c.zlib.compress2(destbuf.ptr, &destlen, cast(ubyte *) srcbuf.ptr, srcbuf.length, level);
207208
if (err)
208209
{
@@ -411,6 +412,7 @@ class Compress
411412
const(void)[] compress(const(void)[] buf)
412413
{
413414
import core.memory : GC;
415+
import std.array : uninitializedArray;
414416
int err;
415417
ubyte[] destbuf;
416418

@@ -425,7 +427,7 @@ class Compress
425427
inited = 1;
426428
}
427429

428-
destbuf = new ubyte[zs.avail_in + buf.length];
430+
destbuf = uninitializedArray!(ubyte[])(zs.avail_in + buf.length);
429431
zs.next_out = destbuf.ptr;
430432
zs.avail_out = to!uint(destbuf.length);
431433

@@ -586,6 +588,7 @@ class UnCompress
586588
return null;
587589

588590
import core.memory : GC;
591+
import std.array : uninitializedArray;
589592
int err;
590593

591594
if (!inited)
@@ -604,7 +607,7 @@ class UnCompress
604607

605608
if (!destbufsize)
606609
destbufsize = to!uint(buf.length) * 2;
607-
auto destbuf = new ubyte[destbufsize];
610+
auto destbuf = uninitializedArray!(ubyte[])(destbufsize);
608611
size_t destFill;
609612

610613
zs.next_in = cast(ubyte*) buf.ptr;

0 commit comments

Comments
 (0)