Skip to content

Commit

Permalink
[interp] throw overflow exception when {float,double}.NaN is converte…
Browse files Browse the repository at this point in the history
…d to an int type (#11411)

A comparison with NaN is always `false`.
  • Loading branch information
monojenkins authored and luhenry committed Oct 28, 2018
1 parent 6034c58 commit 0522076
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
1 change: 0 additions & 1 deletion mcs/class/corlib/Test/System/ConvertTest.cs
Expand Up @@ -4916,7 +4916,6 @@ public void ToInt32_NaN ()
}

[Test]
[Category ("NotWorkingRuntimeInterpreter")]
public void ChangeTypeFromInvalidDouble ()
{
// types which should generate OverflowException from double.NaN, etc.
Expand Down
8 changes: 4 additions & 4 deletions mono/mini/interp/interp.c
Expand Up @@ -4566,13 +4566,13 @@ interp_exec_method_full (InterpFrame *frame, ThreadContext *context, guint16 *st
++ip;
MINT_IN_BREAK;
MINT_IN_CASE(MINT_CONV_OVF_U8_R4)
if (sp [-1].data.f_r4 < 0 || sp [-1].data.f_r4 > G_MAXUINT64)
if (sp [-1].data.f_r4 < 0 || sp [-1].data.f_r4 > G_MAXUINT64 || isnan (sp [-1].data.f_r4))
THROW_EX (mono_get_exception_overflow (), ip);
sp [-1].data.l = (guint64)sp [-1].data.f_r4;
++ip;
MINT_IN_BREAK;
MINT_IN_CASE(MINT_CONV_OVF_U8_R8)
if (sp [-1].data.f < 0 || sp [-1].data.f > G_MAXUINT64)
if (sp [-1].data.f < 0 || sp [-1].data.f > G_MAXUINT64 || isnan (sp [-1].data.f))
THROW_EX (mono_get_exception_overflow (), ip);
sp [-1].data.l = (guint64)sp [-1].data.f;
++ip;
Expand All @@ -4584,13 +4584,13 @@ interp_exec_method_full (InterpFrame *frame, ThreadContext *context, guint16 *st
++ip;
MINT_IN_BREAK;
MINT_IN_CASE(MINT_CONV_OVF_I8_R4)
if (sp [-1].data.f_r4 < G_MININT64 || sp [-1].data.f_r4 > G_MAXINT64)
if (sp [-1].data.f_r4 < G_MININT64 || sp [-1].data.f_r4 > G_MAXINT64 || isnan (sp [-1].data.f_r4))
THROW_EX (mono_get_exception_overflow (), ip);
sp [-1].data.l = (gint64)sp [-1].data.f_r4;
++ip;
MINT_IN_BREAK;
MINT_IN_CASE(MINT_CONV_OVF_I8_R8)
if (sp [-1].data.f < G_MININT64 || sp [-1].data.f > G_MAXINT64)
if (sp [-1].data.f < G_MININT64 || sp [-1].data.f > G_MAXINT64 || isnan (sp [-1].data.f))
THROW_EX (mono_get_exception_overflow (), ip);
sp [-1].data.l = (gint64)sp [-1].data.f;
++ip;
Expand Down

0 comments on commit 0522076

Please sign in to comment.