Fixed: Avoid zero-length array memory allocations

pull/2/head
Qstick 4 years ago
parent 295b975046
commit 4ec71538b9

@ -190,8 +190,6 @@ dotnet_diagnostic.CA1821.severity = suggestion
dotnet_diagnostic.CA1822.severity = suggestion
dotnet_diagnostic.CA1823.severity = suggestion
dotnet_diagnostic.CA1824.severity = suggestion
dotnet_diagnostic.CA1825.severity = suggestion
dotnet_diagnostic.CA1826.severity = suggestion
dotnet_diagnostic.CA2000.severity = suggestion
dotnet_diagnostic.CA2002.severity = suggestion
dotnet_diagnostic.CA2007.severity = suggestion

@ -1,3 +1,4 @@
using System;
using System.IO;
using System.Linq;
using Nancy;
@ -57,7 +58,7 @@ namespace NzbDrone.Api.FileSystem
if (!_diskProvider.FolderExists(path))
{
return new string[0];
return Array.Empty<string>();
}
return _diskScanService.GetVideoFiles(path).Select(f => new

@ -1,3 +1,4 @@
using System;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Common.EnvironmentInfo;
@ -11,7 +12,7 @@ namespace NzbDrone.Common.Test.EnvironmentTests
[Test]
public void empty_array_should_return_empty_flags()
{
var args = new StartupContext(new string[0]);
var args = new StartupContext(Array.Empty<string>());
args.Flags.Should().BeEmpty();
}

@ -100,7 +100,7 @@ namespace NzbDrone.Common.Test.Http
Mocker.SetConstant<ICacheManager>(Mocker.Resolve<CacheManager>());
Mocker.SetConstant<ICreateManagedWebProxy>(Mocker.Resolve<ManagedWebProxyFactory>());
Mocker.SetConstant<IRateLimitService>(Mocker.Resolve<RateLimitService>());
Mocker.SetConstant<IEnumerable<IHttpRequestInterceptor>>(new IHttpRequestInterceptor[0]);
Mocker.SetConstant<IEnumerable<IHttpRequestInterceptor>>(Array.Empty<IHttpRequestInterceptor>());
Mocker.SetConstant<IHttpDispatcher>(Mocker.Resolve<TDispatcher>());
// Used for manual testing of socks proxies.
@ -352,7 +352,7 @@ namespace NzbDrone.Common.Test.Http
var oldRequest = new HttpRequest($"https://{_httpBinHost2}/get");
oldRequest.Cookies["my"] = "cookie";
var oldClient = new HttpClient(new IHttpRequestInterceptor[0], Mocker.Resolve<ICacheManager>(), Mocker.Resolve<IRateLimitService>(), Mocker.Resolve<IHttpDispatcher>(), Mocker.Resolve<Logger>());
var oldClient = new HttpClient(Array.Empty<IHttpRequestInterceptor>(), Mocker.Resolve<ICacheManager>(), Mocker.Resolve<IRateLimitService>(), Mocker.Resolve<IHttpDispatcher>(), Mocker.Resolve<Logger>());
oldClient.Should().NotBeSameAs(Subject);

@ -56,7 +56,7 @@ namespace NzbDrone.Common.Http
public string[] GetCookieHeaders()
{
return Headers.GetValues("Set-Cookie") ?? new string[0];
return Headers.GetValues("Set-Cookie") ?? Array.Empty<string>();
}
public Dictionary<string, string> GetCookies()

@ -1,4 +1,5 @@
using NzbDrone.Common.Extensions;
using System;
using NzbDrone.Common.Extensions;
namespace NzbDrone.Common.Http.Proxy
{
@ -41,7 +42,7 @@ namespace NzbDrone.Common.Http.Proxy
return hostlist;
}
return new string[] { };
return Array.Empty<string>();
}
}

@ -298,11 +298,11 @@ namespace TinyIoC
}
catch (System.IO.FileNotFoundException)
{
assemblies = new Type[] { };
assemblies = Array.Empty<Type>();
}
catch (NotSupportedException)
{
assemblies = new Type[] { };
assemblies = Array.Empty<Type>();
}
#if !NETFX_CORE
catch (ReflectionTypeLoadException e)
@ -3355,7 +3355,7 @@ namespace TinyIoC
//#if NETFX_CORE
// MethodInfo resolveMethod = typeof(TinyIoCContainer).GetTypeInfo().GetDeclaredMethods("Resolve").First(mi => !mi.GetParameters().Any());
//#else
MethodInfo resolveMethod = typeof(TinyIoCContainer).GetMethod("Resolve", new Type[] { });
MethodInfo resolveMethod = typeof(TinyIoCContainer).GetMethod("Resolve", Array.Empty<Type>());
//#endif
resolveMethod = resolveMethod.MakeGenericMethod(returnType);
@ -3648,7 +3648,7 @@ namespace TinyIoC
private IEnumerable<TypeRegistration> GetParentRegistrationsForType(Type resolveType)
{
if (_Parent == null)
return new TypeRegistration[] { };
return Array.Empty<TypeRegistration>();
var registrations = _Parent._RegisteredTypes.Keys.Where(tr => tr.Type == resolveType);

@ -89,7 +89,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DelugeTests
Mocker.GetMock<IHttpClient>()
.Setup(s => s.Get(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), new byte[0]));
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), Array.Empty<byte>()));
}
protected void GivenFailedDownload()

@ -34,7 +34,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests
Mocker.GetMock<IHttpClient>()
.Setup(s => s.Get(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), new byte[0]));
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), Array.Empty<byte>()));
Mocker.GetMock<IRemotePathMappingService>()
.Setup(v => v.RemapRemoteToLocal(It.IsAny<string>(), It.IsAny<OsPath>()))

@ -278,7 +278,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
Mocker.GetMock<IHttpClient>()
.Setup(s => s.Get(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), new byte[0]));
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), Array.Empty<byte>()));
_downloadStationConfigItems = new Dictionary<string, object>
{

@ -170,7 +170,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
Mocker.GetMock<IHttpClient>()
.Setup(s => s.Get(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), new byte[0]));
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), Array.Empty<byte>()));
_downloadStationConfigItems = new Dictionary<string, object>
{

@ -86,7 +86,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.HadoukenTests
Mocker.GetMock<IHttpClient>()
.Setup(s => s.Get(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), new byte[0]));
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), Array.Empty<byte>()));
}
protected void GivenFailedDownload()

@ -35,7 +35,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
Mocker.GetMock<IHttpClient>()
.Setup(s => s.Get(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), new byte[0]));
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), Array.Empty<byte>()));
Mocker.GetMock<IQBittorrentProxy>()
.Setup(s => s.GetConfig(It.IsAny<QBittorrentSettings>()))
@ -53,7 +53,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
Mocker.GetMock<IHttpClient>()
.Setup(s => s.Get(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse(r, httpHeader, new byte[0], System.Net.HttpStatusCode.SeeOther));
.Returns<HttpRequest>(r => new HttpResponse(r, httpHeader, Array.Empty<byte>(), System.Net.HttpStatusCode.SeeOther));
}
protected void GivenRedirectToTorrent()
@ -63,7 +63,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
Mocker.GetMock<IHttpClient>()
.Setup(s => s.Get(It.Is<HttpRequest>(h => h.Url.FullUri == _downloadUrl)))
.Returns<HttpRequest>(r => new HttpResponse(r, httpHeader, new byte[0], System.Net.HttpStatusCode.Found));
.Returns<HttpRequest>(r => new HttpResponse(r, httpHeader, Array.Empty<byte>(), System.Net.HttpStatusCode.Found));
}
protected void GivenFailedDownload()
@ -355,7 +355,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
Mocker.GetMock<IQBittorrentProxy>()
.Setup(v => v.MoveTorrentToTopInQueue(It.IsAny<string>(), It.IsAny<QBittorrentSettings>()))
.Throws(new HttpException(new HttpResponse(new HttpRequest("http://me.local/"), new HttpHeader(), new byte[0], System.Net.HttpStatusCode.Forbidden)));
.Throws(new HttpException(new HttpResponse(new HttpRequest("http://me.local/"), new HttpHeader(), Array.Empty<byte>(), System.Net.HttpStatusCode.Forbidden)));
var remoteMovie = CreateRemoteMovie();

@ -537,7 +537,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests
public void should_test_failed_if_tv_sorting_empty()
{
_config.Misc.enable_tv_sorting = true;
_config.Misc.tv_categories = new string[0];
_config.Misc.tv_categories = Array.Empty<string>();
var result = new NzbDroneValidationResult(Subject.Test());

@ -99,7 +99,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.TransmissionTests
Mocker.GetMock<IHttpClient>()
.Setup(s => s.Get(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), new byte[0]));
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), Array.Empty<byte>()));
_transmissionConfigItems = new Dictionary<string, object>();

@ -91,7 +91,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.UTorrentTests
Mocker.GetMock<IHttpClient>()
.Setup(s => s.Get(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), new byte[0]));
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), Array.Empty<byte>()));
}
protected void GivenRedirectToMagnet()
@ -101,7 +101,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.UTorrentTests
Mocker.GetMock<IHttpClient>()
.Setup(s => s.Get(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse(r, httpHeader, new byte[0], System.Net.HttpStatusCode.SeeOther));
.Returns<HttpRequest>(r => new HttpResponse(r, httpHeader, Array.Empty<byte>(), System.Net.HttpStatusCode.SeeOther));
}
protected void GivenRedirectToTorrent()
@ -111,7 +111,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.UTorrentTests
Mocker.GetMock<IHttpClient>()
.Setup(s => s.Get(It.Is<HttpRequest>(h => h.Url.ToString() == _downloadUrl)))
.Returns<HttpRequest>(r => new HttpResponse(r, httpHeader, new byte[0], System.Net.HttpStatusCode.Found));
.Returns<HttpRequest>(r => new HttpResponse(r, httpHeader, Array.Empty<byte>(), System.Net.HttpStatusCode.Found));
}
protected void GivenFailedDownload()

@ -123,7 +123,7 @@ namespace NzbDrone.Core.Test.Download
public void Download_report_should_trigger_indexer_backoff_on_http429_with_long_time()
{
var request = new HttpRequest("http://my.indexer.com");
var response = new HttpResponse(request, new HttpHeader(), new byte[0], (HttpStatusCode)429);
var response = new HttpResponse(request, new HttpHeader(), Array.Empty<byte>(), (HttpStatusCode)429);
response.Headers["Retry-After"] = "300";
var mock = WithUsenetClient();
@ -143,7 +143,7 @@ namespace NzbDrone.Core.Test.Download
public void Download_report_should_trigger_indexer_backoff_on_http429_based_on_date()
{
var request = new HttpRequest("http://my.indexer.com");
var response = new HttpResponse(request, new HttpHeader(), new byte[0], (HttpStatusCode)429);
var response = new HttpResponse(request, new HttpHeader(), Array.Empty<byte>(), (HttpStatusCode)429);
response.Headers["Retry-After"] = DateTime.UtcNow.AddSeconds(300).ToString("r");
var mock = WithUsenetClient();

@ -26,7 +26,7 @@ namespace NzbDrone.Core.Test.Framework
Mocker.SetConstant<IHttpProxySettingsProvider>(new HttpProxySettingsProvider(Mocker.Resolve<ConfigService>()));
Mocker.SetConstant<ICreateManagedWebProxy>(new ManagedWebProxyFactory(Mocker.Resolve<CacheManager>()));
Mocker.SetConstant<IHttpDispatcher>(new ManagedHttpDispatcher(Mocker.Resolve<IHttpProxySettingsProvider>(), Mocker.Resolve<ICreateManagedWebProxy>(), Mocker.Resolve<UserAgentBuilder>(), Mocker.Resolve<IPlatformInfo>(), TestLogger));
Mocker.SetConstant<IHttpClient>(new HttpClient(new IHttpRequestInterceptor[0], Mocker.Resolve<CacheManager>(), Mocker.Resolve<RateLimitService>(), Mocker.Resolve<IHttpDispatcher>(), TestLogger));
Mocker.SetConstant<IHttpClient>(new HttpClient(Array.Empty<IHttpRequestInterceptor>(), Mocker.Resolve<CacheManager>(), Mocker.Resolve<RateLimitService>(), Mocker.Resolve<IHttpDispatcher>(), TestLogger));
Mocker.SetConstant<IRadarrCloudRequestBuilder>(new RadarrCloudRequestBuilder());
}

@ -25,7 +25,7 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
{
Mocker.GetMock<IProvideDownloadClient>()
.Setup(s => s.GetDownloadClients())
.Returns(new IDownloadClient[0]);
.Returns(Array.Empty<IDownloadClient>());
Subject.Check().ShouldBeWarning();
}

@ -93,7 +93,7 @@ namespace NzbDrone.Core.Test.MediaFiles
private void WasImportedResponse()
{
Mocker.GetMock<IDiskScanService>().Setup(c => c.GetVideoFiles(It.IsAny<string>(), It.IsAny<bool>()))
.Returns(new string[0]);
.Returns(System.Array.Empty<string>());
}
[Test]
@ -142,7 +142,7 @@ namespace NzbDrone.Core.Test.MediaFiles
Mocker.GetMock<IDiskScanService>()
.Setup(c => c.GetVideoFiles(It.IsAny<string>(), It.IsAny<bool>()))
.Returns(new string[0]);
.Returns(System.Array.Empty<string>());
Subject.ProcessRootFolder(new DirectoryInfo(_droneFactory));

@ -1,3 +1,4 @@
using System;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
@ -103,9 +104,9 @@ namespace NzbDrone.Core.Test.NotificationTests.EmailTests
[Test]
public void should_not_be_valid_if_to_bcc_cc_are_all_empty()
{
_emailSettings.To = new string[] { };
_emailSettings.CC = new string[] { };
_emailSettings.Bcc = new string[] { };
_emailSettings.To = Array.Empty<string>();
_emailSettings.CC = Array.Empty<string>();
_emailSettings.Bcc = Array.Empty<string>();
_validator.Validate(_emailSettings).IsValid.Should().BeFalse();
}

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Text.Json;
@ -49,8 +50,8 @@ namespace NzbDrone.Core.Datastore.Migration
Password = settings.Password,
From = settings.From,
To = new string[] { settings.To },
CC = new string[] { },
Bcc = new string[] { }
CC = Array.Empty<string>(),
Bcc = Array.Empty<string>()
};
corrected.Add(new ProviderDefinition166

@ -349,7 +349,7 @@ namespace NzbDrone.Core.Download.Clients.Deluge
{
if (result.Torrents == null)
{
return new DelugeTorrent[0];
return Array.Empty<DelugeTorrent>();
}
return result.Torrents.Values.ToArray();

@ -106,7 +106,7 @@ namespace NzbDrone.Core.Download.Clients.Hadouken
{
if (torrentsRaw == null)
{
return new HadoukenTorrent[0];
return Array.Empty<HadoukenTorrent>();
}
var torrents = new List<HadoukenTorrent>();

@ -17,7 +17,7 @@ namespace NzbDrone.Core.Download.TrackedDownloads
public TrackedDownload()
{
StatusMessages = new TrackedDownloadStatusMessage[] { };
StatusMessages = System.Array.Empty<TrackedDownloadStatusMessage>();
}
public void Warn(string message, params object[] args)

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using FluentValidation;
using NzbDrone.Core.Annotations;
@ -23,8 +24,8 @@ namespace NzbDrone.Core.ImportLists.Radarr
{
BaseUrl = "";
ApiKey = "";
ProfileIds = new int[] { };
TagIds = new int[] { };
ProfileIds = Array.Empty<int>();
TagIds = Array.Empty<int>();
}
[FieldDefinition(0, Label = "Full URL", HelpText = "URL, including port, of the Radarr V3 instance to import from")]

@ -28,8 +28,8 @@ namespace NzbDrone.Core.Indexers.HDBits
MinimumSeeders = IndexerDefaults.MINIMUM_SEEDERS;
Categories = new int[] { (int)HdBitsCategory.Movie };
Codecs = new int[0];
Mediums = new int[0];
Codecs = System.Array.Empty<int>();
Mediums = System.Array.Empty<int>();
MultiLanguages = new List<int>();
RequiredFlags = new List<int>();
}

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FluentValidation;
@ -35,9 +36,9 @@ namespace NzbDrone.Core.Notifications.Email
Port = 587;
Ssl = true;
To = new string[] { };
CC = new string[] { };
Bcc = new string[] { };
To = Array.Empty<string>();
CC = Array.Empty<string>();
Bcc = Array.Empty<string>();
}
[FieldDefinition(0, Label = "Server", HelpText = "Hostname or IP of Email server")]

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using FluentValidation;
using NzbDrone.Core.Annotations;
@ -20,8 +21,8 @@ namespace NzbDrone.Core.Notifications.PushBullet
public PushBulletSettings()
{
DeviceIds = new string[] { };
ChannelTags = new string[] { };
DeviceIds = Array.Empty<string>();
ChannelTags = Array.Empty<string>();
}
[FieldDefinition(0, Label = "Access Token", HelpLink = "https://www.pushbullet.com/#settings/account")]

@ -23,7 +23,7 @@ namespace NzbDrone.Core.Notifications.Pushover
public PushoverSettings()
{
Priority = 0;
Devices = new string[] { };
Devices = System.Array.Empty<string>();
}
//TODO: Get Pushover to change our app name (or create a new app) when we have a new logo

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using FluentValidation;
using NzbDrone.Core.Annotations;
@ -24,7 +25,7 @@ namespace NzbDrone.Core.Notifications.SendGrid
public SendGridSettings()
{
BaseUrl = "https://api.sendgrid.com/v3/";
Recipients = new string[] { };
Recipients = Array.Empty<string>();
}
public string BaseUrl { get; set; }

@ -1,3 +1,4 @@
using System;
using System.IO;
using FluentAssertions;
using Moq;
@ -44,7 +45,7 @@ namespace NzbDrone.Mono.Test.EnvironmentInfo.VersionAdapters
Subject.Read().Should().BeNull();
Mocker.GetMock<IDiskProvider>()
.Setup(c => c.GetFiles(It.IsAny<string>(), SearchOption.TopDirectoryOnly)).Returns(new string[0]);
.Setup(c => c.GetFiles(It.IsAny<string>(), SearchOption.TopDirectoryOnly)).Returns(Array.Empty<string>());
Subject.Read().Should().BeNull();
}

@ -53,7 +53,7 @@ namespace NzbDrone.Test.Common
{
_mocker = new AutoMoqer();
_mocker.SetConstant<ICacheManager>(new CacheManager());
_mocker.SetConstant<IStartupContext>(new StartupContext(new string[0]));
_mocker.SetConstant<IStartupContext>(new StartupContext(Array.Empty<string>()));
_mocker.SetConstant(TestLogger);
}

@ -1,3 +1,4 @@
using System;
using System.IO;
using System.Linq;
using Nancy;
@ -57,7 +58,7 @@ namespace Radarr.Api.V3.FileSystem
if (!_diskProvider.FolderExists(path))
{
return new string[0];
return Array.Empty<string>();
}
return _diskScanService.GetVideoFiles(path).Select(f => new

Loading…
Cancel
Save