History

String constructor now permits length of 0 with non-null - This was useful when using static buffers that don't have content. Ensure the syscall error message buffer is properly initialized.

arr committed 9 years ago

Commit 058335e1 parent 0643d043 files · +9 −4Browse files

Unified · Split

3 files
  1. src/vm/string.cpp +4 −1
  2. src/vm/sys/sys_utils.h +2 −2
  3. src/vm/vm.cpp +3 −1
src/vm/string.cpp+4−1
@@ -190,7 +190,10 @@ vm_string_t::vm_string_t(std::size_t encoded_str_len, const uint8_t *encoded_str · 189 unmodified lines
190 , _length_max{ sizeof(_mem.local) }190 , _length_max{ sizeof(_mem.local) }
191 , _mem{}191 , _mem{}
192{192{
193 assert((encoded_str_len > 0 && encoded_str != nullptr) || (encoded_str_len == 0 && encoded_str == nullptr));193 assert((encoded_str_len > 0 && encoded_str != nullptr) || encoded_str_len == 0);
194 if (encoded_str_len == 0)
195 encoded_str = nullptr;
196
194 const auto utf8_length = utf8::count_codepoints(encoded_str, encoded_str_len);197 const auto utf8_length = utf8::count_codepoints(encoded_str, encoded_str_len);
195 198
196 // Check if the supplied string is completely valid UTF-8 - only valid UTF-8 strings can be DisVM strings.199 // Check if the supplied string is completely valid UTF-8 - only valid UTF-8 strings can be DisVM strings.
src/vm/sys/sys_utils.h+2−2
@@ -41,8 +41,8 @@ namespace disvm · 40 unmodified lines
41 enum class cfs_flags_t41 enum class cfs_flags_t
42 {42 {
43 none = 0,43 none = 0,
44 atomic = 1,44 atomic = 1 << 0,
45 ensure_create = 2,45 ensure_create = 1 << 1,
46 };46 };
47 47
48 DEFINE_ENUM_FLAG_OPERATORS(cfs_flags_t);48 DEFINE_ENUM_FLAG_OPERATORS(cfs_flags_t);
src/vm/vm.cpp+3−1
@@ -91,7 +91,8 @@ vm_config_t::vm_config_t(vm_config_t &&other) · 90 unmodified lines
91{ }91{ }
92 92
93vm_t::vm_t()93vm_t::vm_t()
94 : _last_syscall_error_message_lock{ ATOMIC_FLAG_INIT }94 : _last_syscall_error_message{}
95 , _last_syscall_error_message_lock{ ATOMIC_FLAG_INIT }
95{96{
96 // Initialize built-in modules.97 // Initialize built-in modules.
97 builtin::initialize_builtin_modules();98 builtin::initialize_builtin_modules();
@@ -102,6 +103,7 @@ vm_t::vm_t() · 4 unmodified lines
102}103}
103 104
104vm_t::vm_t(vm_config_t config)105vm_t::vm_t(vm_config_t config)
106 : _last_syscall_error_message{}
105{107{
106 // Initialize built-in modules.108 // Initialize built-in modules.
107 builtin::initialize_builtin_modules();109 builtin::initialize_builtin_modules();