Skip to content

Commit a36c4ef

Browse files
committed
Merge pull request #1778 from pguyot:w30/fix-empty-atom-esp32
Fix a bug where empty atom could not be decoded on esp32 (Note: before merging, the original 2 commits have been squashed together) These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license). SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
2 parents 82a5e3d + be94d85 commit a36c4ef

File tree

5 files changed

+52
-4
lines changed

5 files changed

+52
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7171
- Utilize reserved `phy_init` partition on ESP32 to store wifi calibration for faster connections.
7272
- Support for zero count in `lists:duplicate/2`.
7373
- packbeam: fix memory leak preventing building with address sanitizer
74+
- Fixed a bug where empty atom could not be created on some platforms, thus breaking receiving a message for a registered process from an OTP node.
7475

7576
## [0.6.7] - Unreleased
7677

src/libAtomVM/atom_table.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,11 +388,13 @@ enum AtomTableEnsureAtomResult atom_table_ensure_atom(struct AtomTable *table, c
388388

389389
if (opts & AtomTableCopyAtom) {
390390
uint8_t *buf = malloc(atom_len);
391-
if (IS_NULL_PTR(buf)) {
392-
SMP_UNLOCK(table);
393-
return AtomTableEnsureAtomAllocFail;
391+
if (atom_len > 0) {
392+
if (IS_NULL_PTR(buf)) {
393+
SMP_UNLOCK(table);
394+
return AtomTableEnsureAtomAllocFail;
395+
}
396+
memcpy(buf, atom_data, atom_len);
394397
}
395-
memcpy(buf, atom_data, atom_len);
396398
atom_data = buf;
397399
}
398400

src/platforms/esp32/test/main/test_erl_sources/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ endfunction()
4040
compile_erlang(test_esp_partition)
4141
compile_erlang(test_file)
4242
compile_erlang(test_wifi_example)
43+
compile_erlang(test_list_to_atom)
4344
compile_erlang(test_list_to_binary)
4445
compile_erlang(test_md5)
4546
compile_erlang(test_crypto)
@@ -61,6 +62,7 @@ add_custom_command(
6162
test_esp_partition.beam
6263
test_file.beam
6364
test_wifi_example.beam
65+
test_list_to_atom.beam
6466
test_list_to_binary.beam
6567
test_md5.beam
6668
test_crypto.beam
@@ -79,6 +81,7 @@ add_custom_command(
7981
"${CMAKE_CURRENT_BINARY_DIR}/test_esp_partition.beam"
8082
"${CMAKE_CURRENT_BINARY_DIR}/test_wifi_example.beam"
8183
"${CMAKE_CURRENT_BINARY_DIR}/test_file.beam"
84+
"${CMAKE_CURRENT_BINARY_DIR}/test_list_to_atom.beam"
8285
"${CMAKE_CURRENT_BINARY_DIR}/test_list_to_binary.beam"
8386
"${CMAKE_CURRENT_BINARY_DIR}/test_md5.beam"
8487
"${CMAKE_CURRENT_BINARY_DIR}/test_crypto.beam"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
%
2+
% This file is part of AtomVM.
3+
%
4+
% Copyright 2025 Paul Guyot <[email protected]>
5+
%
6+
% Licensed under the Apache License, Version 2.0 (the "License");
7+
% you may not use this file except in compliance with the License.
8+
% You may obtain a copy of the License at
9+
%
10+
% http://www.apache.org/licenses/LICENSE-2.0
11+
%
12+
% Unless required by applicable law or agreed to in writing, software
13+
% distributed under the License is distributed on an "AS IS" BASIS,
14+
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
% See the License for the specific language governing permissions and
16+
% limitations under the License.
17+
%
18+
% SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
19+
%
20+
21+
-module(test_list_to_atom).
22+
23+
-export([start/0]).
24+
25+
start() ->
26+
ok = test_empty_list_to_atom(),
27+
ok.
28+
29+
test_empty_list_to_atom() ->
30+
Atom = erlang:list_to_atom(id([])),
31+
true = is_atom(id(Atom)),
32+
[] = erlang:atom_to_list(id(Atom)),
33+
ok.
34+
35+
id(X) ->
36+
X.

src/platforms/esp32/test/main/test_main.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,12 @@ TEST_CASE("test_file", "[test_run]")
289289
}
290290
#endif
291291

292+
TEST_CASE("test_list_to_atom", "[test_run]")
293+
{
294+
term ret_value = avm_test_case("test_list_to_atom.beam");
295+
TEST_ASSERT(ret_value == OK_ATOM);
296+
}
297+
292298
TEST_CASE("test_list_to_binary", "[test_run]")
293299
{
294300
term ret_value = avm_test_case("test_list_to_binary.beam");

0 commit comments

Comments
 (0)