From 1f014f724c22daa604db5a0a16ee2b8865e15e64 Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Tue, 23 Jul 2024 13:04:44 -0700 Subject: [PATCH] Fix Zero length check --- src/StackExchange.Redis/PhysicalConnection.cs | 8 ++++---- src/StackExchange.Redis/RedisKey.cs | 6 +++--- src/StackExchange.Redis/RedisResult.cs | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/StackExchange.Redis/PhysicalConnection.cs b/src/StackExchange.Redis/PhysicalConnection.cs index c282121a5..8faa4a798 100644 --- a/src/StackExchange.Redis/PhysicalConnection.cs +++ b/src/StackExchange.Redis/PhysicalConnection.cs @@ -1,7 +1,9 @@ -using Pipelines.Sockets.Unofficial; +using Microsoft.Extensions.Logging; +using Pipelines.Sockets.Unofficial; using Pipelines.Sockets.Unofficial.Arenas; using System; using System.Buffers; +using System.Buffers.Binary; using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; @@ -17,9 +19,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; -using Microsoft.Extensions.Logging; using static StackExchange.Redis.Message; -using System.Buffers.Binary; namespace StackExchange.Redis { @@ -91,7 +91,7 @@ public PhysicalConnection(PhysicalBridge bridge) connectionType = bridge.ConnectionType; _bridge = new WeakReference(bridge); ChannelPrefix = bridge.Multiplexer.RawConfig.ChannelPrefix; - if (ChannelPrefix?.Length == 0) ChannelPrefix = null; // null tests are easier than null+empty + if (ChannelPrefix == null || ChannelPrefix.Length == 0) ChannelPrefix = null; // null tests are easier than null+empty var endpoint = bridge.ServerEndPoint.EndPoint; _physicalName = connectionType + "#" + Interlocked.Increment(ref totalCount) + "@" + Format.ToString(endpoint); diff --git a/src/StackExchange.Redis/RedisKey.cs b/src/StackExchange.Redis/RedisKey.cs index 28378d116..144201ba5 100644 --- a/src/StackExchange.Redis/RedisKey.cs +++ b/src/StackExchange.Redis/RedisKey.cs @@ -13,7 +13,7 @@ namespace StackExchange.Redis { internal RedisKey(byte[]? keyPrefix, object? keyValue) { - KeyPrefix = keyPrefix?.Length == 0 ? null : keyPrefix; + KeyPrefix = keyPrefix == null || keyPrefix.Length == 0 ? null : keyPrefix; KeyValue = keyValue; } @@ -253,7 +253,7 @@ public static implicit operator RedisKey(byte[]? key) /// Obtain the as a . /// /// The key to get a byte array for. - public static implicit operator byte[]? (RedisKey key) + public static implicit operator byte[]?(RedisKey key) { if (key.IsNull) return null; if (key.TryGetSimpleBuffer(out var arr)) return arr; @@ -270,7 +270,7 @@ public static implicit operator RedisKey(byte[]? key) /// Obtain the key as a . /// /// The key to get a string for. - public static implicit operator string? (RedisKey key) + public static implicit operator string?(RedisKey key) { if (key.KeyPrefix is null) { diff --git a/src/StackExchange.Redis/RedisResult.cs b/src/StackExchange.Redis/RedisResult.cs index bf094f8af..826eaca99 100644 --- a/src/StackExchange.Redis/RedisResult.cs +++ b/src/StackExchange.Redis/RedisResult.cs @@ -401,7 +401,7 @@ internal override bool AsBoolean() : Array.ConvertAll(_value, x => x.AsByteArray()!); private bool IsSingleton => _value?.Length == 1; - private bool IsEmpty => _value?.Length == 0; + private bool IsEmpty => _value == null || _value.Length == 0; internal override double AsDouble() { if (IsSingleton) return _value![0].AsDouble();