-
Notifications
You must be signed in to change notification settings - Fork 423
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
Binary prefix in c++ strings #1674
Comments
I don't think that is true. 😕 Did you try enabling |
It is like that. It is actually possible to push NULL characters in c++ string, but they have to be added as chars. #include <iostream>
#include <string>
int main() {
std::string s = "abc\0def"; // this will contain only abc
std::cout << s << std::endl;
s.push_back('\0'); // now it contains also a NULL.
std::cout << s << std::endl;
} And yes, I already tried out the option. It is actually the binary replacement that created hard problems to debug, because NULLs are not trivial to see in the output ;-) |
Sorry, I really don't understand how conda-build triggers this problem (not that it doesn't - just having a hard time understanding what a fix would be). Would it help if the prefix replacement didn't include the NULL character? |
@dolfim: Perhaps you could write your code so that it does dynamic relocation? |
Let me explain better what is going on. (I don't think that not having NULLs helps) Some introduction:
Now, what happens with
In my example workaround I do the following:
I know it is very subtle as a problem, it took me some time to come up with this understanding... |
@mingwandroid : the function you propose isn't in the standard library, right? |
I'm proposing you set Whatever folder you want relative to the prefix, you dynamically calculate based on those three functions. I'd be surprised if someone hasn't written a BSD or a Public Domain wrapper for getting the executable's (or shared library's) PATH using the methods I outlined above. The functions I detailed are in |
This is for sure a possibility, now I solved it already with the workaround I posted above. Additionally, we also have a mechanism in place to provide the installation prefix via env variables which I set in the loading of the conda venv This is not anymore an issue for me, but it could for other users, therefore I didn't close it yet. I leave it up to you to decide if to consider a fix, documenting the workaround, or do nothing. |
I'm running into this problem, when trying to make a conda recipe for cppcheck. See conda-forge/cppcheck-feedstock#8. Strings in the C++ standard library are indeed not null-terminated, which seems to be related to this issue. I'm not a developer of cppcheck, so I can't easily change the source code to avoid using https://github.com/danmar/cppcheck/blob/19e9e42dd7fc8ba327a2736cc091285d37faff80/lib/library.cpp#L99 I've only seen this problem with clangxx (on osx) and not with gxx. It seems that clangxx is compiling string literals directly into
(See https://en.cppreference.com/w/cpp/language/string_literal) That effectively means that any string literal in C++ source code has to be a C-style null-terminated string, no matter how it is compiled. |
P.S. Is there a way to build everything on OSX with gcc instead of clang? That would be a simple solution. |
It really would not be simple at all, trust me on that. |
ok, thanks. I'll open an issue on the cppcheck project then to suggest to support some form of dynamic relocation as you suggested above, which is in the end still the nicest solution. |
cc @SylvainCorlay @wolfv (in case this is relevant) |
…he conda build/run process, see conda/conda-build#1674
Merge PR #20099, commits were: * Patch percolator Globals.cpp to avoid null termination problem with the conda build/run process, see conda/conda-build#1674 * Merge branch 'master' into perco_testmsgf * Add tandem2pin, msgf2pin tests to recipe, both failing
Just battled the same problem for a couple of hours, until I understood it sufficiently to know what to Google for. Just wanted to thank @dolfim for sharing the As the amount of C++ code (compiled w. modern compilers) grows, this issue may become more frequent. Is there a good place in the |
FWIW marking strings as volatile can help here. See #2524. |
Hi there, thank you for your contribution! This issue has been automatically marked as stale because it has not had recent activity. It will be closed automatically if no further activity occurs. If you would like this issue to remain open please:
NOTE: If this issue was closed prematurely, please leave a comment. Thanks! |
Can someone please reopen this issue? AFAIK it remains unsolved |
DEFENV_VERILATOR_ROOT needs to be used as a C-string for conda's install-time relocation patching to work. see also: conda/conda-build#1674
I spent some time struggling with the binary prefix contained in c++ string objects. Here
NULL
characters are not used to terminate strings and can be actual content of a string.The solution I found is:
In
p_wrong
the text is already placed in memory by the compiler and interpreted as a string of >255 characters. The correct version is casting the full text to a c string and calling thestd::string
constructor at runtime which is truncating correctly padding.It is a pity that I had to patch the code for it (and the time invested in finding out the issue).
Is there another way for dealing with this issue?
The text was updated successfully, but these errors were encountered: