[Lldb-commits] [PATCH] Implement snprintf for MSVC with correct return value.
Chaoren Lin
chaorenl at google.com
Wed May 27 10:15:34 PDT 2015
>
> 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.
>
https://memegen.googleplex.com/templateimage?template=burn
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.
On Wed, May 27, 2015 at 9:41 AM, Zachary Turner <zturner at google.com> wrote:
> In http://reviews.llvm.org/D10048#179404, @chaoren wrote:
>
> > > So as far as I can tell the value of `errno` is undefined in the case
> that
> >
> > > `buffer`, `format`, and `count` are all valid, but `count` is just
> not big
> >
> > > enough (which is really the case we're trying to handle anyway).
> >
> >
> > FWIW, I think it's not defined in the MSDN docs because it's already
> > defined in the C standard for all system/library calls.
>
>
> 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.
>
> In any case, I just tested it with this code:
>
> int main(int argc, char* argv[])
> {
> char buffer[10];
>
> errno = 0;
> snprintf(buffer, 10, "This is a test of the snprintf function and
> buffer size");
>
> return 0;
>
> }
>
> When `snprintf` calls `_vsnprintf`, `_vsnprintf` returns `-1` as expected,
> and sets `errno` to `34`. So the check is definitely wrong currently.
>
>
> http://reviews.llvm.org/D10048
>
> EMAIL PREFERENCES
> http://reviews.llvm.org/settings/panel/emailpreferences/
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20150527/12b2da58/attachment.html>
More information about the lldb-commits
mailing list