<div dir="ltr"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span style="font-size:12.8000001907349px">Well, the whole reason we have to write this function is because Microsoft's implementation doesn't conform :)  So I don't think we should assume they conform for anything else either.</span><br></blockquote><div><br></div><div><a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__memegen.googleplex.com_templateimage-3Ftemplate-3Dburn&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=MEqT8U_n7oNfuDW5NRbY3ZV384ZquXIYFPWmprwUdKM&m=mawL_HmV9J7kaspj1gCwKvfXnxEOnC0ZP_b8kXsjguQ&s=2EQHwiBtAxiGiaUnbuYp3rHvR9Bm5XVogJq0rDF9GlY&e=">https://memegen.googleplex.com/templateimage?template=burn</a></div><div><br></div>Should we just check for ERANGE (34) then? We need to save and restore errno in that case to conform with the C standards. But I'm not sure about using an undocumented behavior.</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 27, 2015 at 9:41 AM, Zachary Turner <span dir="ltr"><<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">In <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D10048-23179404&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=MEqT8U_n7oNfuDW5NRbY3ZV384ZquXIYFPWmprwUdKM&m=mawL_HmV9J7kaspj1gCwKvfXnxEOnC0ZP_b8kXsjguQ&s=pBIn1vJxDzYTukhFiLiXLvum5i5rD8pDA6tHsLyAEEs&e=" target="_blank">http://reviews.llvm.org/D10048#179404</a>, @chaoren wrote:<br>
<br>
> > So as far as I can tell the value of `errno` is undefined in the case that<br>
><br>
> >  `buffer`, `format`, and `count` are all valid, but `count` is just not big<br>
><br>
> >  enough (which is really the case we're trying to handle anyway).<br>
><br>
><br>
> FWIW, I think it's not defined in the MSDN docs because it's already<br>
>  defined in the C standard for all system/library calls.<br>
<br>
<br>
</span>Well, the whole reason we have to write this function is because Microsoft's implementation doesn't conform :)  So I don't think we should assume they conform for anything else either.<br>
<br>
In any case, I just tested it with this code:<br>
<br>
  int main(int argc, char* argv[])<br>
  {<br>
      char buffer[10];<br>
<br>
      errno = 0;<br>
      snprintf(buffer, 10, "This is a test of the snprintf function and buffer size");<br>
<br>
return 0;<br>
<br>
  }<br>
<br>
When `snprintf` calls `_vsnprintf`, `_vsnprintf` returns `-1` as expected, and sets `errno` to `34`.  So the check is definitely wrong currently.<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D10048&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=MEqT8U_n7oNfuDW5NRbY3ZV384ZquXIYFPWmprwUdKM&m=mawL_HmV9J7kaspj1gCwKvfXnxEOnC0ZP_b8kXsjguQ&s=DhIG0JKTkBErLYNhvfKP4ONhTUBIIVqkmb3uE92lf48&e=" target="_blank">http://reviews.llvm.org/D10048</a><br>
<br>
EMAIL PREFERENCES<br>
  <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_settings_panel_emailpreferences_&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=MEqT8U_n7oNfuDW5NRbY3ZV384ZquXIYFPWmprwUdKM&m=mawL_HmV9J7kaspj1gCwKvfXnxEOnC0ZP_b8kXsjguQ&s=05ojg3NclJhR1Q6wT7PbBYzhm0T4TaUo7lkFKXzQd-Y&e=" target="_blank">http://reviews.llvm.org/settings/panel/emailpreferences/</a><br>
<br>
<br>
</div></div></blockquote></div><br></div>