mirror of
https://github.com/dlang/phobos.git
synced 2025-04-27 13:40:20 +03:00
std.zlib.crc32 and std.zlib.adler32 64-bit underflow|error when processing over 2^32 bytes of data fix
This commit is contained in:
parent
4efb875a7a
commit
f79af5f018
1 changed files with 12 additions and 3 deletions
15
std/zlib.d
15
std/zlib.d
|
@ -67,8 +67,12 @@ class ZlibException : Exception
|
|||
|
||||
uint adler32(uint adler, const(void)[] buf)
|
||||
{
|
||||
return etc.c.zlib.adler32(adler, cast(ubyte *)buf.ptr,
|
||||
to!uint(buf.length));
|
||||
import std.range : chunks;
|
||||
foreach(chunk; (cast(ubyte[])buf).chunks(0xFFFF0000))
|
||||
{
|
||||
adler = etc.c.zlib.adler32(adler, chunk.ptr, cast(uint)chunk.length);
|
||||
}
|
||||
return adler;
|
||||
}
|
||||
|
||||
unittest
|
||||
|
@ -90,7 +94,12 @@ unittest
|
|||
|
||||
uint crc32(uint crc, const(void)[] buf)
|
||||
{
|
||||
return etc.c.zlib.crc32(crc, cast(ubyte *)buf.ptr, to!uint(buf.length));
|
||||
import std.range : chunks;
|
||||
foreach(chunk; (cast(ubyte[])buf).chunks(0xFFFF0000))
|
||||
{
|
||||
crc = etc.c.zlib.crc32(crc, chunk.ptr, cast(uint)chunk.length);
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
unittest
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue