Skip to content

Commit

Permalink
Fix unsafe conversion from Char to int
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MDoerner committed Nov 8, 2023
1 parent 32da47c commit f3254a0
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Rubberduck.Parsing/VBA/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit f3254a0

Please sign in to comment.