mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 09:31:58 +00:00
[vm/io] Null-terminate scope-copied CStrings.
Fixes https://github.com/dart-lang/sdk/issues/54741 TEST=standalone/io/io_override_test Change-Id: Ie907360dc4bcea05ef6fe3a5d4626e4e31399fc6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/348723 Commit-Queue: Alexander Aprelev <aam@google.com> Reviewed-by: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
parent
55310a1c70
commit
1d1531c8d9
|
@ -56,8 +56,9 @@ intptr_t TypedDataScope::size_in_bytes() const {
|
|||
}
|
||||
|
||||
const char* TypedDataScope::GetScopedCString() const {
|
||||
char* buf = reinterpret_cast<char*>(Dart_ScopeAllocate(size_in_bytes()));
|
||||
char* buf = reinterpret_cast<char*>(Dart_ScopeAllocate(size_in_bytes() + 1));
|
||||
strncpy(buf, GetCString(), size_in_bytes());
|
||||
buf[size_in_bytes()] = '\0';
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue