<div dir="ltr">But you forgot that 

  (IS_SAFE_STRUCT_SIZE((a), (m), (n)) ? ((func)((a) + (size_t)(m) * (size_t)(n))) : FAILURE_RESULT) is not the same equivalence to 

  (IS_SAFE_STRUCT_SIZE((a), (m), (n)) ? ((func)((size_t)(a) + (size_t)(m) * (size_t)(n))) : FAILURE_RESULT)<div>because of the ((func)((size_t)(a) + (size_t)(m) * (size_t)(n))</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le mar. 8 nov. 2022 à 14:59, Alexey Ivanov <<a href="mailto:aivanov@openjdk.org">aivanov@openjdk.org</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Mon, 7 Nov 2022 22:04:55 GMT, Alexander Zuev <<a href="mailto:kizune@openjdk.org" target="_blank">kizune@openjdk.org</a>> wrote:<br>
<br>
> Removed the additional multiplication overflow detection.<br>
> Instead cast all the parameters to type_t just the way they are treated in the existing size check macro. <br>
> This way there is no possibility to accidentally provide parameters that will pass the size check macro while being cast to size_t there but then due to the missing cast cause the wrong size passed the actual allocation function.<br>
> Since this checking macro was used in couple of different places all of them needs to be updated in the similar way.<br>
<br>
Changes requested by aivanov (Reviewer).<br>
<br>
src/java.desktop/share/native/common/awt/utility/sizecalc.h line 95:<br>
<br>
> 93: #define SAFE_SIZE_NEW_ARRAY2(type, n, m) \<br>
> 94:     (IS_SAFE_SIZE_MUL((m), (n)) && IS_SAFE_SIZE_MUL(sizeof(type), (n) * (m)) ? \<br>
> 95:      (new type[(size_t)((n) * (m))]) : throw std::bad_alloc())<br>
<br>
Suggestion:<br>
<br>
     (new type[(size_t)(n) * (size_t)(m)]) : throw std::bad_alloc())<br>
<br>
Each parameter must be cast as in `SAFE_SIZE_ARRAY_ALLOC`.<br>
<br>
src/java.desktop/share/native/common/awt/utility/sizecalc.h line 115:<br>
<br>
> 113:  */<br>
> 114: #define SAFE_SIZE_STRUCT_ALLOC(func, a, m, n) \<br>
> 115:     (IS_SAFE_STRUCT_SIZE((a), (m), (n)) ? ((func)((a) + (size_t)(m) * (size_t)(n))) : FAILURE_RESULT)<br>
<br>
Suggestion:<br>
<br>
    (IS_SAFE_STRUCT_SIZE((a), (m), (n)) ? ((func)((size_t)(a) + (size_t)(m) * (size_t)(n))) : FAILURE_RESULT)<br>
<br>
To be safe, `a` should also be cast.<br>
<br>
And `IS_SAFE_STRUCT_SIZE` should also be updated to pass `(size_t)(m) * (size_t)(n)` to `IS_SAFE_SIZE_ADD` instead of `(m) * (n)`.<br>
<br>
-------------<br>
<br>
PR: <a href="https://git.openjdk.org/jdk/pull/11030" rel="noreferrer" target="_blank">https://git.openjdk.org/jdk/pull/11030</a><br>
</blockquote></div>