File 1195-erts-Add-warning-in-erl_nif-doc-about-match-state-pr.patch of Package erlang
From a4007c0204f9b5b513a70cbf893ae0795afc4684 Mon Sep 17 00:00:00 2001
From: Sverker Eriksson <sverker@erlang.org>
Date: Wed, 27 Jan 2021 20:17:30 +0100
Subject: [PATCH] erts: Add warning in erl_nif doc about match state problem
---
erts/doc/src/erl_nif.xml | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/erts/doc/src/erl_nif.xml b/erts/doc/src/erl_nif.xml
index d2a1581e35..57bff58db4 100644
--- a/erts/doc/src/erl_nif.xml
+++ b/erts/doc/src/erl_nif.xml
@@ -140,6 +140,21 @@ $> erl
However, unused local stub functions will be optimized
away by the compiler, causing loading of the NIF library to fail.</p>
</note>
+ <warning>
+ <p>
+ There is a known limitation for Erlang fallback functions of NIFs. Avoid
+ functions involved in traversal of binaries by matching and
+ recursion. If a NIF is loaded over such function, binary arguments to
+ the NIF may get corrupted and cause VM crash or other misbehavior.
+ </p>
+ <p>Example of such bad fallback function:</p>
+ <code type="none">
+skip_until(Byte, <<Byte, Rest/binary>>) ->
+ Rest;
+skip_until(Byte, <<_, Rest/binary>>) ->
+ skip_until(Byte, Rest).
+</code>
+ </warning>
</section>
<section>
--
2.26.2