{"id":43933,"date":"2014-10-02T07:00:00","date_gmt":"2014-10-02T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2014\/10\/02\/in-the-red-corner-exception_int_divide_by_zero-and-status_integer_divide_by_zero-and-in-the-blue-corner-exception_int_overflow-and-status_integer_overflow\/"},"modified":"2014-10-02T07:00:00","modified_gmt":"2014-10-02T07:00:00","slug":"in-the-red-corner-exception_int_divide_by_zero-and-status_integer_divide_by_zero-and-in-the-blue-corner-exception_int_overflow-and-status_integer_overflow","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20141002-00\/?p=43933","title":{"rendered":"In the red corner, EXCEPTION_INT_DIVIDE_BY_ZERO and STATUS_INTEGER_DIVIDE_BY_ZERO; and in the blue corner, EXCEPTION_INT_OVERFLOW and STATUS_INTEGER_OVERFLOW"},"content":{"rendered":"<p>The exception code <code>EXCEPTION_INT_DIVIDE_BY_ZERO<\/code> (and its doppelg&auml;nger <code>STATUS_INTEGER_DIVIDE_BY_ZERO<\/code>) is raised, naturally enough, when the denominator of an integer division is zero.\n The x86 and x64 processors also raise this exception when <a href=\"http:\/\/web.archive.org\/web\/20111128085612\/http:\/\/my.opera.com\/taviso\/blog\/show.dml\/639454\"> you divide <code>INT_MIN<\/code> by <code>-1<\/code><\/a>, or more generally, when the result of a division does not fit in the destination. The division instructions for those processors take a 2<var>N<\/var>-bit dividend and an <var>N<\/var>-bit divisor, and they produce <var>N<\/var>-bit quotient and remainder. Values of <var>N<\/var> can be 8, 16, and 32; the 64-bit processors also support 64. And the division can be signed or unsigned. Therefore, you can get this exception if you try to divide, say, 2&sup3;&sup2; by 1, using a 64-bit dividend and 32-bit divisor. The quotient is 2&sup3;&sup2;, which does not fit in a 32-bit divisor.\n The Windows&nbsp;95 kernel does not attempt to distinguish between division overflow and division by zero. It just converts the processor exception to <code>EXCEPTION_INT_DIVIDE_BY_ZERO<\/code> and calls it a day.\n The Windows&nbsp;NT kernel realizes that the underlying processor exception is ambiguous and tries to figure out why the division operation failed. If the divisor is zero, then the exception is reported as <code>EXCEPTION_INT_DIVIDE_BY_ZERO<\/code>. If the divisor is nonzero, then the exception is reported as <code>EXCEPTION_INT_OVERFLOW<\/code>.\n Another place that <code>EXCEPTION_INT_OVERFLOW<\/code> can arise from a processor exception is if an application issues the <code>INTO<\/code> instruction and the overflow flag is set.<\/p>\n<p> <b>Puzzle<\/b>: The <code>DIV<\/code> and <code>IDIV<\/code> instructions support a divisor in memory. What happens if the memory becomes inaccessible after the processor raises the exception but before the kernel can read the value in order to check whether it is zero? What other things could go wrong? <\/p>\n","protected":false},"excerpt":{"rendered":"<p>The exception code EXCEPTION_INT_DIVIDE_BY_ZERO (and its doppelg&auml;nger STATUS_INTEGER_DIVIDE_BY_ZERO) is raised, naturally enough, when the denominator of an integer division is zero. The x86 and x64 processors also raise this exception when you divide INT_MIN by -1, or more generally, when the result of a division does not fit in the destination. The division instructions for [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-43933","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>The exception code EXCEPTION_INT_DIVIDE_BY_ZERO (and its doppelg&auml;nger STATUS_INTEGER_DIVIDE_BY_ZERO) is raised, naturally enough, when the denominator of an integer division is zero. The x86 and x64 processors also raise this exception when you divide INT_MIN by -1, or more generally, when the result of a division does not fit in the destination. The division instructions for [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/43933","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=43933"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/43933\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=43933"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=43933"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=43933"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}