TString warning - Input string is shorter than requested size

ATLAS has upgraded to the recent LCG release with a newer ROOT version (6.26.08) and as usual this brings new unexpected “features”. One of my applications now issues millions of warnings of this kind:

Warning in <TString::TString>: Input string is shorter than requested size.
Warning in <TString::TString>: Input string is shorter than requested size.
Warning in <TString::TString>: Input string is shorter than requested size.
Warning in <TString::TString>: Input string is shorter than requested size.
Warning in <TString::TString>: Input string is shorter than requested size.

Looking at github it seem that the reason is this commit: Added Warning to TString constuctor · root-project/root@8aa2f14 · GitHub
I think this change is pointless, and it breaks a reasonable existing interface without giving an option to do what we need to do in an alternative way. We do store long binary strings in TString, and this is the interface that worked for us before and you broke it. Please remove this commit and avoid doing pointless changes in the future that silently break functionality :angry:

Doesn’t the warning happens when you do something like:

TString mystring("short", 100);

Where `TString is then asking to copy 94 characters past the end of the string? Isn’t that dangerous?

This code is definitely dangerous, but issuing a warning is pointless, because you continue with the copy of the data and that is an undefined behavior.

This code OTOH, is not dangerous and this is how things work for us now, and it should never result in a warning:

char buffer[1024];
// fill buffer with a data.
TString string_buffer(buffer, 1024);

Edit: if you want to make your API safer, and deprecate unsafe methods, you should provide an adequate safer replacement for this method, e.g. using constructor from std::string_view instances.

Apologies for my latest rant, TString indeed has a constructor from std::string_view, I somehow missed it browsing through sources. Maybe a warning should mention that std::string_view constructor exists.
OTOH I do believe that it’s none of TString business warning me that I’m doing something potentially unsafe. std::string, which is a similar class, used much more widely, newer issues any warnings.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.