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
190190 , _length_max{ sizeof(_mem.local) }
191191 , _mem{}
192192 {
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+
194197 const auto utf8_length = utf8::count_codepoints(encoded_str, encoded_str_len);
195198
196199 // 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
4141 enum class cfs_flags_t
4242 {
4343 none = 0,
44− atomic = 1,
45− ensure_create = 2,
44+ atomic = 1 << 0,
45+ ensure_create = 1 << 1,
4646 };
4747
4848 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
9191 { }
9292
9393 vm_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 }
9596 {
9697 // Initialize built-in modules.
9798 builtin::initialize_builtin_modules();
@@ -102,6 +103,7 @@ vm_t::vm_t() · 4 unmodified lines
102103 }
103104
104105 vm_t::vm_t(vm_config_t config)
106+ : _last_syscall_error_message{}
105107 {
106108 // Initialize built-in modules.
107109 builtin::initialize_builtin_modules();