[PATCH] D107654: [Flang] Fix error messages on Windows.

Michael Kruse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 10 19:25:16 PDT 2021


Meinersbur added inline comments.


================
Comment at: flang/lib/Parser/message.cpp:44
+  // used in some messages.
+  int need{_vsprintf_p(nullptr, 0, p, ap)};
+#else
----------------
amccarth wrote:
> I understand the intent is to determine the size of the buffer needed, but the [Microsoft documentation for `_vsprintf_p`][1] says,
> 
> > If the buffer or format parameters are NULL pointers, ... the invalid parameter handler is invoked, as described in Parameter Validation. If execution is allowed to continue, the functions return -1 and set errno to EINVAL.
> 
> But since this is passing a null pointer for the buffer, I'd expect this to abort or return -1.  Maybe that's a documentation bug.  Has this been tested on Windows?
> 
> [1]: https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/vsprintf-p-vsprintf-p-l-vswprintf-p-vswprintf-p-l?view=msvc-160#remarks
This seems to be a documentation bug. The Windows SDK source explicitly checks for a NULL argument for the buffer and returns the length [1].

The behaviour isn't document for the standard vsprintf function either, see [2] or [3].

The pre-merge buildbot would be running this code in D107575 (if it was rebased). I tested it myself and it is working.

[1] https://github.com/huangqinjin/ucrt/blob/a52376780e631fb0e5d520748addb03651aef0b5/stdio/output.cpp#L169
[2] https://www.cplusplus.com/reference/cstdio/vsprintf/
[3] https://linux.die.net/man/3/vsprintf


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107654/new/

https://reviews.llvm.org/D107654



More information about the llvm-commits mailing list