Skip to content

Commit 173c57f

Browse files
whatyouhideJosé Valim
authored andcommitted
Fix a possible binary leak in Integer.parse/1
Integer.parse/1 followed this pattern: defp do_parse(<<char, rest :: binary>>, ...) do ... # instead of re-using the original binary, we do this {..., <<char, rest :: binary>>} end This causes a new binary to be created instead of `rest` just being a sub-binary. Signed-off-by: José Valim <[email protected]>
1 parent 737ac62 commit 173c57f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/elixir/lib/integer.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,11 @@ defmodule Integer do
167167

168168
defp do_parse(_, _), do: :error
169169

170-
defp do_parse(<<char, rest::binary>>, base, acc) do
170+
defp do_parse(<<char, rest::binary>> = bin, base, acc) do
171171
if valid_digit_in_base?(char, base) do
172172
do_parse(rest, base, base * acc + parse_digit(char, base))
173173
else
174-
{acc, <<char, rest::binary>>}
174+
{acc, bin}
175175
end
176176
end
177177

0 commit comments

Comments
 (0)