Skip to content

Commit

Permalink
downloader: Check read bytes before appending to buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
ximion committed Jan 28, 2021
1 parent bf4fe21 commit 69c3eab
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/asgen/downloader.d
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,8 @@ public:
scope(exit) g_object_unref (stream);

ptrdiff_t len;
ubyte[GENERIC_BUFFER_SIZE] buffer;
do {
ubyte[GENERIC_BUFFER_SIZE] buffer;

len = g_input_stream_read (stream, cast(void*)buffer.ptr, cast(size_t)buffer.length, null, null);
if (len > 0)
dFile.rawWrite (buffer[0..len]);
Expand All @@ -206,11 +205,11 @@ public:

auto result = appender!(ubyte[]);
ptrdiff_t len;
ubyte[GENERIC_BUFFER_SIZE] buffer;
do {
ubyte[GENERIC_BUFFER_SIZE] buffer;

len = g_input_stream_read (stream, cast(void*)buffer.ptr, cast(size_t)buffer.length, null, null);
result ~= buffer[0..len];
if (len > 0)
result ~= buffer[0..len];
} while (len > 0);

return result.data;
Expand Down

0 comments on commit 69c3eab

Please sign in to comment.