menu.c: use puts() instead of printf() where possible
PATCH 1/1 menu.c: use puts() instead of printf() where possible
common/menu.c used printf() in a number of places to print user provided, constant strings (like the "title" string). printf() is dangerous here for example in case the user unwittingly embeds some '%' caracters that printf() would interpret as formatting and then pick up random arguments. Use puts() instead.
We also omit the trailing ':' in the title line - if a user wants this, he can provide it as part of the title string.
---
total: 0 errors, 0 warnings, 35 lines checked
NOTE: Ignored message types: COMPLEX_MACRO CONSIDER_KSTRTO MINMAX MULTISTATEMENT_MACRO_USE_DO_WHILE /tmp/patch has no obvious style problems and is ready for submission.
common/menu.c | 16 ++++++++++------ 1 files changed, 10 insertions(+), 6 deletions(-)
common/menu.c +10 -6
@@ -87,10 +87,12 @@ static inline void *menu_item_print(struct menu *m, struct menu_item *item, void *extra) { -if (!m->item_data_print) -printf ("%s\n" , item->key); -else +if (!m->item_data_print) { +putc (item->key); +putc ('\n' ); + }else { m->item_data_print (item->data); + }return NULL ; }
@@ -117,8 +119,10 @@ static inline void *menu_item_destroy(struct menu *m,*/ static inline void menu_display (struct menu *m) { -if (m->title) -printf ("%s:\n" , m->title); +if (m->title) { +puts (m->title); +putc ('\n' ); + }menu_items_iter (m, menu_item_print,NULL ); }
@@ -226,7 +230,7 @@ static inline int menu_interactive_choice(struct menu *m, void **choice)if (!choice_item)printf ("%s not found\n" , cbuf); }else { -printf ("^C\n" ); +puts ("^C\n" );return -EINTR ; } }
Signature · 1 line
1.7.6.4
PATCH 1/1 menu.c: use puts() instead of printf() where possible
Quoted 5 lines · On Monday 28 November 2011 14:24:49 Wolfgang Denk wrote:
common/menu.cusedprintf()in a number of places to print user provided, constant strings (like the "title" string).printf()is dangerous here for example in case the user unwittingly embeds some '%' caracters thatprintf()would interpret as formatting and then pick up random arguments. Useputs()instead.
i'm not seeing this problem based on your patch below ...
common/menu.c static inline void *menu_item_print(struct menu *m, · line 92
Quoted 7 lines
common/menu.c +2
-2-if (!m->item_data_print) -printf ("%s\n" , item->key); +putc (item->key); +putc ('\n' );
item->key is not passed as the first arg, so % sequences would not get interpreted
common/menu.c static inline void *menu_item_destroy(struct menu *m, · line 124
Quoted 3 lines
common/menu.c +2
-1-printf ("%s:\n" , m->title); +puts (m->title); +putc ('\n' );
same here
common/menu.c static inline int menu_interactive_choice(struct menu *m, void **choice) · line 233
Quoted 2 lines
common/menu.c +1
-1-printf ("^C\n" ); +puts ("^C\n" );
this change makes sense, but not for any of the reasons cited in the changelog; this looks like a simple optimization ...
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20111128/f5b1ecac/attachment.pgp>
PATCH 1/1 menu.c: use puts() instead of printf() where possible
Dear Mike Frysinger,
Quoted 9 lines · In message <[email protected]> you wrote:
Quoted 5 lines · On Monday 28 November 2011 14:24:49 Wolfgang Denk wrote:
common/menu.cusedprintf()in a number of places to print user provided, constant strings (like the "title" string).printf()is dangerous here for example in case the user unwittingly embeds some '%' caracters thatprintf()would interpret as formatting and then pick up random arguments. Useputs()instead.i'm not seeing this problem based on your patch below ...
Yes, you are right. I was incorrectly extrapolating from another issue fixed elsewhere.
Quoted 5 lines
common/menu.c static inline int menu_interactive_choice(struct menu *m, void **choice) · line 233
Quoted 2 lines
common/menu.c +1
-1-printf ("^C\n" ); +puts ("^C\n" );this change makes sense, but not for any of the reasons cited in the changelog; this looks like a simple optimization ...
True. But d*mn, I have messed this up, and it sneaked into the master branch already.
Sorry...
Best regards,
Wolfgang Denk
Signature · 6 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
If there was anything that depressed him more than his own cynicism,
it was that quite often it still wasn't as cynical as real life.
- Terry Pratchett, _Guards! Guards!_