Re: [Powertop] [PATCH] Use printf, not sprintf, to print messages to stdout.

Magnus Fromreide <magfr at lysator.liu.se> Fri, 22 Jun 2012 10:49:30 +0200
Newsgroups dev.linux.lists.powertop
Message-ID <1340354970.2997.14.camel@sara>
On Fri, 2012-06-22 at 08:45 +0200, Holger Schurig wrote:
> You guys should run powertop via clang's static analyzer :-)

Ok, I did.

It found a few bugs, but not these. On the other hand, the compiler
warned about these.

The warnings from g++ for this particular problem are:

main.cpp: In function ‘void out_of_memory()’:
main.cpp:234:72: warning: deprecated conversion from string constant to ‘char*’ 
[-Wwrite-strings]
main.cpp: In function ‘int main(int, char**)’:
main.cpp:465:39: warning: deprecated conversion from string constant to ‘char*’ 

>From clang++ I get:

main.cpp:234:10: warning: conversion from string literal to 'char *' is deprecated [-Wdeprecated-writable-strings]
        sprintf("%s...\n",_("PowerTOP is out of memory. PowerTOP is Aborting"));
                ^
main.cpp:465:10: warning: conversion from string literal to 'char *' is deprecated [-Wdeprecated-writable-strings]
        sprintf("%s\n", _("Leaving PowerTOP"));
                ^

>From clang-analyze I get nothing.

The most interesting part is actually that the compilers reported this
as a warning and not an error.

/MF