I have actually a small role to do plots indigenous a TTree:void drawHist(TChain* chain, const char* variable, .. )

in i m sorry I additionally construct from the variable to do the fileName String, miscellaneous like

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

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

I understand what it means, however is feasible to deal with this centrally? indigenous the TString I check out what ns am act 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 ----------------------------------------------------------------- | Welcome to source 6.13/01 http://root.couchsurfingcook.com.ch | | (c) 1995-2017, The source Team | | built for macosx64 | | indigenous heads/master
behrenhoff December 12, 2017, 1:45pm #3
wherein did you gain the type signature from?From https://root.couchsurfingcook.com.ch/root/html602/TString.html#TString:Form:

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

So you have actually removed the “…” from the debate list. Kind is favor printf, i.e. It parses her input. In your case, it will fail as shortly as you have a percent authorize (%) in your variable.

I guess you carry out not need type at all. Simply use

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

hejb December 12, 2017, 1:58pm #4
couet being a lazy physicist… it is why i asked whether this can be done centrally.

behrenhoff Yes, it appears I perform not require Form, “=” works perfect, at least it no complain. Thanks!

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

You have to fix that in her code, it can not be done centrally. The method you did it works many of the time but is an extremely error prone and should thus be avoided. The warning (note: not an error) even tells girlfriend one means to settle it (as demonstrated by Olivier)

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

it appears I do not require Form

“Form” does more than just appending a string. You have the right to do any type of text formatting.The intake is different than the an easy “=” . Together your initial instance had “Form” i made a functioning one through “Form” too …

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

This subject was instantly closed 14 job after the critical reply. New replies are no much longer allowed.

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

residence Categories FAQ/Guidelines state of service Privacy policy

Powered by Discourse, ideal viewed through JavaScript enabled