Skip to content

Commit

Permalink
fixup! erts: Refactor bitstring (binary) handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jhogberg committed Nov 16, 2023
1 parent abb786e commit af8e9ed
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions erts/emulator/beam/erl_iolist.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,38 +129,43 @@ enum iolist_action generic_iolist_size(ErtsIOListState *state,
L_start:
while (is_list(obj)) {
Eterm *cell = list_val(obj);
Eterm head, tail;

if ((YieldSupport) && --yield_count <= 0) {
goto L_yield;
}

obj = CAR(cell);
/* Note that we don't update `obj` straight away: if we have to
* bail on a size overflow, we don't want to return into the main
* loop with the raw `head` as that may be a type error. */
head = CAR(cell);
tail = CDR(cell);

if (is_byte(obj)) {
if (is_byte(head)) {
if (ERTS_UNLIKELY(size > (ERTS_UWORD_MAX - 8))) {
ESTACK_PUSH(s, CDR(cell));
goto L_overflow;
}
size += 8;
} else if (is_bitstring(obj)) {
Uint obj_size = bitstring_size(obj);
if ((obj_size % (Unit)) != 0) {
} else if (is_bitstring(head)) {
Uint head_size = bitstring_size(head);
if ((head_size % (Unit)) != 0) {
goto L_type_error;
}
if (ERTS_UNLIKELY(size > (ERTS_UWORD_MAX - obj_size))) {
ESTACK_PUSH(s, CDR(cell));
if (ERTS_UNLIKELY(size > (ERTS_UWORD_MAX - head_size))) {
goto L_overflow;
}
size += obj_size;
} else if (is_list(obj)) {
/* Deal with the inner list in `obj` first, handling our tail
size += head_size;
} else if (is_list(head)) {
/* Deal with the inner list in `head` first, handling our tail
* later */
ESTACK_PUSH(s, CDR(cell));
ESTACK_PUSH(s, tail);
obj = head;
continue;
} else if (is_not_nil(obj)) {
} else if (is_not_nil(head)) {
goto L_type_error;
}

obj = CDR(cell);
obj = tail;
}

if ((YieldSupport) && --yield_count <= 0) {
Expand Down

0 comments on commit af8e9ed

Please sign in to comment.