I have actually a tiny function to make plots from a TTree:void drawHist(TChain* chain, const char* variable, .. )

in which I likewise construct from the variable to make the fileName String, something like

//... TString epsName; epsName.Form(variable); epsName += ".eps"; //...This functions perfectly via root5, however now via root6, it constantly complain:

18: warning: format string is not a string literal (potentially insecure) <-Wformat-security>epsName.Form(variable);^~~~~~~~…C:107:18: note: treat the string as an debate to stop thisepsName.Form(variable);^"%s",

I understand what it means, however is possible to fix this centrally? From the TString I view what I am doing is valid:voidForm(const char* fmt)

Thanks a lot!




You are watching: Format string is not a string literal

couet December 12, 2017, 1:45pm #2

void str( const char* variable) { TString epsName; epsName = Form("%s.eps",variable); cout $ root ----------------------------------------------------------------- | Welpertained to ROOT 6.13/01 http://root.couchsurfingcook.com.ch | | (c) 1995-2017, The ROOT Team | | Built for macosx64 | | From heads/master
behrenhoff December 12, 2017, 1:45pm #3
Wbelow did you gain the Form signature from?From https://root.couchsurfingcook.com.ch/root/html602/TString.html#TString:Form:

void Form(const char *va_(fmt), …)Formats a string utilizing a printf style format descriptor.

So you have rerelocated the “…” from the discussion list. Form is prefer printf, i.e. it parses your input. In your case, it will fail as soon as you have actually a percent authorize (%) in your variable.

I guess you do not require Form at all. Just use

TString epsName = variable;epsName += ".eps";(or similar code)


hejb December 12, 2017, 1:58pm #4
couet Being a lazy physicist… That’s why I asked whether this might be done centrally.
*

behrenhoff Yes, it appears I execute not require Form, “=” works perfect, at leastern it doesn’t comsimple. Thanks!


behrenhoff December 12, 2017, 2:06pm #5

You need to settle it in your code, it cannot be done centrally. The way you did it works a lot of of the moment yet is exceptionally error vulnerable and also have to therefore be avoided. The warning (note: not an error) even tells you one way to resolve it (as demonstrated by Olivier)


couet December 12, 2017, 2:07pm #6
*
hejb:

it seems I do not require Form

“Form” does even more than just appfinishing a string. You have the right to execute any kind of text formatting.The intake is different than the straightforward “=” . As your initial instance had actually “Form” I made a functioning one through “Form” too …


system closed December 26, 2017, 2:07pm #7

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




See more: Is One Direction'S ' Drag Me Down Group That Won 14 Across In 2013 2 Wds

Home Categories FAQ/Guidelines Terms of Service Privacy Policy

Powered by Discourse, finest viewed through JavaScript enabled