On 6/12/19 10:02 AM, Brian Burkhalter wrote:
Actually, never mind, I am being completely lame here: both
NET_ThrowNew() and the Windows function LocalFree() are robust to a
NULL-valued buf so I think we can just remove the n > 0 or buf == NULL
check altogether.
That's true, assuming that you initialize buf = NULL and hopping that
FormatMessage won't change buf upon failure.
I wish MSDN were a little bit more specific here.
I am fine with
1)
362 TCHAR *buf = NULL;
2)
unconditional
395 NET_ThrowNew(env, err, buf);
396 LocalFree(buf);
With kind regards,
Ivan
Sorry for the noise: I should have checked this first.
Thanks,
Brian
On Jun 12, 2019, at 9:51 AM, Brian Burkhalter
<brian.burkhal...@oracle.com <mailto:brian.burkhal...@oracle.com>> wrote:
I am perhaps beating a dead horse here, but how about this instead?
if (n > 0) {
NET_ThrowNew(env, err, buf);
LocalFree(buf);
} else {
NET_ThrowNew(env, err, "FormatMessage failed");
}
After all, an error *did* occur.
--
With kind regards,
Ivan Gerasimov