diff --git a/runtime/bin/typed_data_utils.cc b/runtime/bin/typed_data_utils.cc index 7d4169273da..c07fb603cee 100644 --- a/runtime/bin/typed_data_utils.cc +++ b/runtime/bin/typed_data_utils.cc @@ -56,8 +56,9 @@ intptr_t TypedDataScope::size_in_bytes() const { } const char* TypedDataScope::GetScopedCString() const { - char* buf = reinterpret_cast(Dart_ScopeAllocate(size_in_bytes())); + char* buf = reinterpret_cast(Dart_ScopeAllocate(size_in_bytes() + 1)); strncpy(buf, GetCString(), size_in_bytes()); + buf[size_in_bytes()] = '\0'; return buf; } diff --git a/tests/standalone/io/io_override_test.dart b/tests/standalone/io/io_override_test.dart index 79d3925478c..816b54c7401 100644 --- a/tests/standalone/io/io_override_test.dart +++ b/tests/standalone/io/io_override_test.dart @@ -293,8 +293,19 @@ globalIOOverridesZoneTest() { Expect.isTrue(dir is Directory); } +class EmptyOverride extends IOOverrides {} + +void emptyIOOverride() { + IOOverrides.runWithIOOverrides( + () => Expect.equals( + FileSystemEntity.typeSync('/'), FileSystemEntityType.directory), + EmptyOverride(), + ); +} + main() async { await ioOverridesRunTest(); globalIOOverridesTest(); globalIOOverridesZoneTest(); + emptyIOOverride(); }