From f3254a0c88013dd723a09875b0886f17c085f257 Mon Sep 17 00:00:00 2001 From: Max Doerner Date: Wed, 8 Nov 2023 21:05:39 +0100 Subject: [PATCH] Fix unsafe conversion from Char to int It is not safe to convert from Char to int16, since the unicode code points are unsigned 16-bit integers. The safe conversion it to int32, as also indicated in the docs. --- Rubberduck.Parsing/VBA/Extensions/StringExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rubberduck.Parsing/VBA/Extensions/StringExtensions.cs b/Rubberduck.Parsing/VBA/Extensions/StringExtensions.cs index 1e3890d19b..dc95202661 100644 --- a/Rubberduck.Parsing/VBA/Extensions/StringExtensions.cs +++ b/Rubberduck.Parsing/VBA/Extensions/StringExtensions.cs @@ -148,7 +148,7 @@ public static string ToVbExpression(this string managed, bool useConsts = true) var literal = string.Empty; foreach (var character in managed.ToCharArray()) { - var unicode = Convert.ToInt16(character) > byte.MaxValue; + var unicode = Convert.ToInt32(character) > byte.MaxValue; var specialCased = VbCharacterConstants.ContainsKey(character); if (specialCased || char.IsControl(character) && !unicode) {