Git Product home page Git Product logo

Comments (4)

dunhor avatar dunhor commented on August 26, 2024

Your code as written currently has a bug. Before formatting the message, WIL will "widen" the format string (to ensure that there's no "loss" of data when formatting Unicode strings). You should explicitly specify %hs for narrow char* strings

from wil.

dunhor avatar dunhor commented on August 26, 2024

More info from the documentation:

Be explicit when logging strings with XXXX_MSG macros. Use either: %ls or %hs to control whether an argument is a wide or ascii string, rather than using %s or %S. The format string is expected to be ASCII to minimize binary size, but internally is printed Unicode to avoid loss of data from params. Use the explicit format specifier to avoid the ambiguity this can bring.

from wil.

brycehutchings avatar brycehutchings commented on August 26, 2024

Thanks, I will fix it. If wil is interpreting a format string that is provided as char* as if it is wide, is there a way to provide a more helpful error message? Even if the comment on __WI_CHECK_MSG_FMT explained this, then I would have been able to fix the problem without opening this issue. As it is, this wil design is surprising and not everyone updating to a new version of wil will be familiar with this requirement.

from wil.

dunhor avatar dunhor commented on August 26, 2024

is there a way to provide a more helpful error message?

Depends on which part of the error message you find unhelpful. IIRC the vast majority of error messages I saw said something like:

warning C4477: 'wprintf' : format string '%s' requires an argument of type 'wchar_t *', but variadic argument 1 has type 'const char *'
note: consider using '%hs' in the format string
note: consider using '%Ts' in the format string
note: this warning is based on non-standard semantics used by Visual C++

That's fairly specific. The most confusing part is the reference to wprintf. AFAIK there's no way to make that part better for two reasons:

  1. The check done by the compiler seems to be hard coded based off function name. Therefore, we have a limited set of options in terms of triggering the warning as something like _Printf_format_string_ is unfortunately not checked by the compiler and you instead have to run additional tools to get warnings (e.g. compiling with /analyze)
  2. Even if the above were resolved, and _Printf_format_string_ (or some other attribute) did work, we'd need a way to communicate to the compiler that we're going to be widening the string

Even if the comment on __WI_CHECK_MSG_FMT explained this, then I would have been able to fix the problem without opening this issue

If there's verbiage that would have been more helpful, feel free to submit a PR to clarify things.

from wil.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.