Re: Use (f)puts instead of (f)printf when possible.
Pascal Bourguignon <[email protected]>
| Newsgroups | gmane.lisp.clisp.devel |
|---|---|
| Message-ID | <[email protected]> |
> On 24 Aug 2017, at 23:11, Bruno Haible <[email protected]> wrote: > > Hi Sam, > >> Use (f)puts instead of (f)printf when possible. > > I guess this was motivated by Jerry's remark: > > ! Fedora builds with -Werror=format-security, so I had to change > ! one line in the aarch64 patch. That patch modifies spvw_allocate.d > ! and in one place issues a warning. I had to change this line: > ! > ! fprintf(stderr, GETTEXTL("Warning: “)); > ! > ! to: > ! > ! fputs(GETTEXTL("Warning: "),stderr); > ! > ! since the string is non-constant, and therefore triggers the format > ! security error. > The standard way to avoid it is to use a literal format string! fprintf(stderr,”%s”,GETTEXTL(“Warning: “)); > Therefore I've introduced two macros > > /* Use fprintf and printf only for format strings that take at least 1 argument. > For literal strings, use print and fprint. > Avoid using fputs, puts, fputc, putc, putchar directly, because these APIs > are hard to memorize (fputs, fputc, putc don't take the stream first; puts > outputs an extra newline) or redundant (fputc, putc, putchar are special > cases of fputs that GCC recognizes anyway). */ > #define fprint(fp,string) fputs(string,fp) > #define print(string) fputs(string,stdout) At first, I thought that fprint would take a format string (why fprint(fp,“3 %%”); prints two percent characters?). At second, it feels like a typo! I would prefer fputs... -- __Pascal J. Bourguignon__ ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ clisp-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/clisp-devel