New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use %zu for printf-style formatting of size_t values. #19339
Conversation
This is a semi-automated replacement of %d/%i formats with %zu when the parameter is of type size_t. It was driven by parsing the warnings generated by PRINTF_CHECKS. Also fixes one case where a size_t was passed as a width specifier (this has to be an int) %zu is specified in C++11 (via C99) so hopefully we are OK with compatibility there. The alternatives are very ugly (macros embedded in format strings, or casts everywhere)
According to stackoverflow thread, VS2013 doesn't support |
VS2013 also doesn't support C++11, does it? My research seemed to indicate that the more recent visual studio versions that supported C++11, also supported %zu. |
http://stackoverflow.com/questions/15610053/correct-printf-format-specifier-for-size-t-zu-or-iu suggests that VS2015 does support %zu, VS2013 may or may not it's unclear. What are we targeting? (VS2013 apparently doesn't support constexpr either..) |
Okay, I've checked
So you PR is acceptable. |
This breaks the Windows release by causing a crash when opening the new inventory UI. |
What is the Windows release built with? |
MXE cross compiles with MinGW, most likely 4.8.2 from #13652. |
Looks like we might need https://stackoverflow.com/questions/25670522/c-program-shows-zu-after-conversion-to-windows I have no way of testing this. |
Maybe @narc0tiq can check if the flag is applicable to the build. This issue isn't present on MSYS2/mingw gcc 5.2.0. |
Yeah, I tested these charges with Code::Blocks default compiler in Windows and it woorks fine. |
It seems that this PR needs to be reverted, sorry for this. Is it ok to just push the 'revert' button or we have some more gentle and safe way to do that? |
Shouldn't we revert the PR until the solution is applied? BTW the link that @mutability gave suggests a [quick]fix:
|
@illi-kun At the same time. |
That's all right. The side effect wasn't easily predictable.
Pushing it creates a reverting pull request. I believe that's perfectly safe. |
So what's the plan for actually fixing the build issue? I can't test the change I suggested, is there an active developer with the same build environment (same as the CI environment) who can test it? (if there isn't, that's probably a sign that the CI environment needs to change) |
I can theoretically run builds of specific commits right in Jenkins itself, but that'd show up as a new build and would probably get grabbed up by the auto-updater, so let's avoid that. At the same time, I can also just manually run the same commands in its shell and capture the output. If we're suggesting just that extra |
Okay, here's the wincurses build log and binary taken by checking out this PR (specifically, commit 7dcb672) and adding In my very brief testing, the build is quite unstable; simple things like monsters fighting each other, or eating often (but not always) lead to crashing. This is likely to be the same issue as reported in #19372. [1] Specifically, the invocation was |
OK, so if that didn't work, then options are (in rough order of my preference):
Doing nothing here is just delaying the inevitable as there are surely platforms where passing a size_t to %d is a crash bug. |
The first one appears to be the only viable option. |
Here's a minimalish test; if you can get that compiling in the CI environment such that it says "vector has 1 elements" when run, then it's probably working.
|
Okay. It just worked. Here's the binary. My command was Notably, I left out the |
Hm, weird, why is it failing on the full build then.. |
Ok, so it looks like everything goes through vstring_format in output.cpp which has some _MSC_VER-specific magic that invokes _vscprintf_p and _vsprintf_p. I guess that is bypassing the mingw implementation. The other non-microsoft path uses vsnprintf directly. I wonder if it is simple as dropping the #ifdef _MSC_VER path, can you try turning that ifdef off and using the vsnprintf version? |
I have no real idea about this, the old MXE produces strange results and the new MXE works fine here. |
So I'm working on a new Jenkins and this is funny (but not promising): http://gorgon.narc.ro:8080/job/Cataclysm-Matrix/Graphics=Curses,Platform=Windows_x64/1/console
Hooray for |
Been a long time now since I saw an ICE.. I did only try a 32-bit build. Let me try a 64-bit build. |
I get the same ICE with a 64-bit build. Doesn't happen with a 32-bit (i686) build. |
Actually now that I look at the error, it is a different ICE. Joy.
|
Getting all sorts of ICEs at different locations depending on the exact compile options (but always in expand_expr_addr_expr_1, at expr.c:7672). I do notice this in the Makefile:
perhaps that problem persists in 4.9.4 |
Ah, hey, that could be exactly it! I'll experiment and report back. |
Yeah, it seems to work OK here if I set -O3. Beware that the current makefile detection stuff is broken (it looks at the output of "gcc" not "$(CROSS)gcc"). I'll put together a patch for that. |
…-mingw32.static As seen in CleverRaven#19339
I'm getting an odd issue where the |
No, it's not ccache (it shouldn't have been, so I'm not surprised, but bleh). I need to get back to work; I'll come back to this later. |
As a bit of offtopic: @narc0tiq since you are deploying a new build server (or upgrading existing), could you please install clang/llvm v3.8.1. This will help with linux to mac cross compilation later. You could very simply install it by cloning osxcross and running |
Hell, I can do that to the existing build server right now - I have
packages available, only need to install them. Indeed, on the new machine,
I went straight to clang-3.8 because why not?
…On Thu, Nov 24, 2016, 21:31 patternoia ***@***.***> wrote:
As a bit of offtopic: @narc0tiq <https://github.com/narc0tiq> since you
are deploying a new build server (or upgrading existing), could you please
install clang/llvm *v3.8.1*. This will help with linux to mac cross
compilation later.
You could very simply install it by cloning osxcross
<https://github.com/tpoechtrager/osxcross> and running CLANG_VERSION=3.8.1
INSTALLPREFIX=/any/path/here ./build_clang.sh. By specifying the
INSTALLPREFIX you then ensure you will not damage the current clang
installation.
Let me know what you think about this.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#19339 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAkG1dvjAdq79V7RfmBN_ifFRJdDngvfks5rBeYugaJpZM4K3P7r>
.
|
So, I found out that |
@patternoia I seem to have v3.8.0 on the new machine (but I haven't plugged in the clang PPA, which may resolve it by way of package (much preferable)). Is the .1 critical? |
Should not be |
This is a semi-automated replacement of %d/%i formats with %zu when the parameter is of type size_t. It was driven by parsing the warnings generated by PRINTF_CHECKS. Also fixes one case where a size_t was passed as a width specifier (this has to be an int) Adds a testcase that tests that %zu and positional args work OK. This requires C++ / C99 printf support. The current CI environment does not provide this for Windows builds, so this needs to be merged _after_ the CI environment has been upgraded. (previously: CleverRaven#19339)
Just a project management note, leaving this reverted and trying again
later would be preferable to an invasive workaround, this is a fairly
obscure warning that has very little chance of causing actual problems, and
presumably the underlying projects will have fixes applied in time.
|
What invasive workaround do you mean? Fixing this particular warning is a necessary step towards fixing all the printf warnings, at which point we can turn on enforcement of those warnings in release builds (or as a separate check step) and avoid future bugs involving a mismatch between format strings and arguments. |
I'm not sure it's that invasive, as it's just trading one set of optimizations for another (and it's fairly narrowly targeted at mingw64's x86_64 build target only). We can always narrow it further if someone needs it, but it's more likely mingw64 will update their gcc first... in a couple more years. |
The -O3 thing is just keeping an existing workaround intact with the new
version of gcc, isn't it?
|
Yeah, but with #19440 it's targeted on mingw64 entirely -- which it probably needs, at least for now. Eventually, it'll be unnecessary and we can remove it altogether, I hope. |
Are we building with anything other than gcc 4.9.3 / 4.9.4 for x86_64-w64-mingw32.static? I thought the answer to that was "no" |
It would be useful if Kevin can clarify what he means too because I don't understand what the issue is - the ICE has nothing to do with this PR and you need it anyway? |
I was referring to these options:
1. embed our own printf implementation, e.g.
https://github.com/fmtlib/fmt, either everywhere or just on Windows
builds. NB: this would also fix the existing positional-args problem too I
think.
2. use a macro: ("hey I counted %" PRZU " things", things.size())
3. forbid use of size_t when formatting: ("hey I counted %d things",
(int)things.size())
If it's a targeted fix in the build system my only concern is it being a
time sink, but that's up to the people involved to decide.
|
Yeah, agreed that none of those solutions are particularly good; fixing the CI environment is the way forward. |
This is a semi-automated replacement of %d/%i formats with %zu
when the parameter is of type size_t. It was driven by parsing the
warnings generated by PRINTF_CHECKS.
Also fixes one case where a size_t was passed as a width specifier
(this has to be an int)
%zu is specified in C++11 (via C99) so hopefully we are OK with
compatibility there. The alternatives are very ugly (macros embedded
in format strings, or casts everywhere)