From 8338a6e0669f7460d0b54eec3e94c8000bf0a7b0 Mon Sep 17 00:00:00 2001 From: Bill Zissimopoulos Date: Sun, 7 May 2017 16:29:28 -0700 Subject: [PATCH] tst: memfs-dotnet: fix exceptions in SetFileSizeInternal --- tst/memfs-dotnet/Program.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tst/memfs-dotnet/Program.cs b/tst/memfs-dotnet/Program.cs index dd3b476d..3140ae1b 100644 --- a/tst/memfs-dotnet/Program.cs +++ b/tst/memfs-dotnet/Program.cs @@ -637,8 +637,9 @@ namespace memfs { return STATUS_INSUFFICIENT_RESOURCES; } - Array.Copy(FileNode.FileData, FileData, - (int)Math.Min(FileNode.FileInfo.AllocationSize, NewSize)); + int CopyLength = (int)Math.Min(FileNode.FileInfo.AllocationSize, NewSize); + if (0 != CopyLength) + Array.Copy(FileNode.FileData, FileData, CopyLength); FileNode.FileData = FileData; FileNode.FileInfo.AllocationSize = NewSize; @@ -660,8 +661,11 @@ namespace memfs } if (FileNode.FileInfo.FileSize < NewSize) - Array.Clear(FileNode.FileData, - (int)FileNode.FileInfo.FileSize, (int)(NewSize - FileNode.FileInfo.FileSize)); + { + int CopyLength = (int)(NewSize - FileNode.FileInfo.FileSize); + if (0 != CopyLength) + Array.Clear(FileNode.FileData, (int)FileNode.FileInfo.FileSize, CopyLength); + } FileNode.FileInfo.FileSize = NewSize; } }