Skip to content

Commit ae5189f

Browse files
committed
Fix assertion in 'file_read'
1 parent f0038b4 commit ae5189f

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/file.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ bool file_read(ByteArray* dst,
5353
FILE* fp,
5454
size_t offset_start,
5555
size_t offset_end) {
56-
assert(offset_end >= offset_start);
56+
const bool has_offset_end = (offset_end != 0);
57+
assert(!has_offset_end || offset_end >= offset_start);
5758

5859
/* Allocate and initialize the 'ByteArray' structure */
5960
const size_t initial_size =
@@ -69,7 +70,7 @@ bool file_read(ByteArray* dst,
6970
/* Read the target bytes from the file, resizing it dynamically */
7071
size_t dst_pos;
7172
for (dst_pos = 0;
72-
last_char != EOF && (offset_end == 0 || file_pos < offset_end);
73+
last_char != EOF && (!has_offset_end || file_pos < offset_end);
7374
dst_pos++, file_pos++) {
7475
if (dst_pos >= dst->size && !byte_array_resize(dst, dst->size * 2))
7576
return false;

0 commit comments

Comments
 (0)