Skip to contentSkip to conversation

Use printf, not sprintf, to print messages to stdout.

PATCH In review Magnus Fromreide 4 participants 6 messages Jun 16, 2012 – Jun 22, 2012

lore
Share & tools
lore

Magnus Fromreide

author
#0 lore raw

PATCH 1/1 Use printf, not sprintf, to print messages to stdout.

This undos the last printf->sprintf change from 8fd54ace.

Signed-off-by Magnus Fromreide <magfr(a)lysator.liu.se>
---
 src/main.cpp |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/main.cpp +2 -2
index 880d745..a2d8700 100644
@@ -229,7 +229,7 @@ void one_measurement(int seconds, char *workload)
 void out_of_memory()
 {
 	reset_display();
-	sprintf("%s...\n",_("PowerTOP is out of memory. PowerTOP is Aborting"));
+	printf("%s...\n",_("PowerTOP is out of memory. PowerTOP is Aborting"));
 	abort();
 }
 
@@ -458,7 +458,7 @@ int main(int argc, char **argv)
 #ifndef DISABLE_NCURSES
 	endwin();
 #endif
-	sprintf("%s\n", _("Leaving PowerTOP"));
+	printf("%s\n", _("Leaving PowerTOP"));
 
 	end_process_data();
 	clear_process_data();
Signature · 1 line
1.7.10
author
#1 lore raw

Hello!

Could someone please consider the commneted patch?

It stops powertop from crashing on shutdown.

/MF

#2 lore raw
In reply to Magnus Fromreide
Quoted 22 lines · Magnus Fromreide

This undos the last printf->sprintf change from 8fd54ace.

Signed-off-by Magnus Fromreide <magfr(a)lysator.liu.se>
---
 src/main.cpp |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/main.cpp +1 -1
index 880d745..a2d8700 100644
@@ -229,7 +229,7 @@ void one_measurement(int seconds, char *workload)
 void out_of_memory()
 {
 	reset_display();
-	sprintf("%s...\n",_("PowerTOP is out of memory. PowerTOP is Aborting"));
+	printf("%s...\n",_("PowerTOP is out of memory. PowerTOP is Aborting"));
 	abort();
 }
 

src/main.cpp int main(int argc, char **argv) · line 464

Quoted 8 lines
src/main.cpp +1 -1
@@ -458,7 +458,7 @@ int main(int argc, char **argv)
 #ifndef DISABLE_NCURSES
 	endwin();
 #endif
-	sprintf("%s\n", _("Leaving PowerTOP"));
+	printf("%s\n", _("Leaving PowerTOP"));
 
 	end_process_data();
 	clear_process_data();

Oh, good catch!

Looks like changes were introduced by commit
8fd54ace0a398cd155bf0af620c85d0105778f6a.

	-ss
#3 lore raw
Quoted 15 lines · On Thursday 21 June 2012 22:14:41 Sergey Senozhatsky wrote:
Quoted 14 lines · Magnus Fromreide

This undos the last printf->sprintf change from 8fd54ace.

Signed-off-by Magnus Fromreide <magfr(a)lysator.liu.se>

---

 src/main.cpp |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/main.cpp +0 -0
index 880d745..a2d8700 100644
@@ -229,7 +229,7 @@ void one_measurement(int seconds, char *workload)
 
Quoted 6 lines

src/main.cpp void one_measurement(int seconds, char *workload)

Quoted 6 lines
src/main.cpp +0 -1
 void out_of_memory()
 {
 
 	reset_display();
 
-	sprintf("%s...\n",_("PowerTOP is out of memory. PowerTOP is 

Aborting"));

Quoted 17 lines
Quoted 17 lines
src/main.cpp +1 -0
+	printf("%s...\n",_("PowerTOP is out of memory. PowerTOP is Aborting"));
src/main.cpp +1 -1
 	abort();
 
 }
@@ -458,7 +458,7 @@ int main(int argc, char **argv)
 
 #ifndef DISABLE_NCURSES
 
 	endwin();
 
 #endif
 
-	sprintf("%s\n", _("Leaving PowerTOP"));
+	printf("%s\n", _("Leaving PowerTOP"));
Quoted 7 lines

src/main.cpp int main(int argc, char **argv) · line 464

Quoted 2 lines
src/main.cpp +0 -0
 	end_process_data();
 	clear_process_data();

Oh, good catch!

Looks like changes were introduced by commit
8fd54ace0a398cd155bf0af620c85d0105778f6a.

That commit contains more abuse of sprintf:
https://github.com/fenrus75/powertop/commit/8fd54ace0a398cd155bf0af620c85d0105778f6a#L1L102
Writing to a constant string is not going to work, eh?

Peter

author
#4 lore raw
Quoted 45 lines · Lekensteyn
Quoted 15 lines · On Thursday 21 June 2012 22:14:41 Sergey Senozhatsky wrote:
Quoted 14 lines · Magnus Fromreide

This undos the last printf->sprintf change from 8fd54ace.

Signed-off-by Magnus Fromreide <magfr(a)lysator.liu.se>

---

 src/main.cpp |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/main.cpp +0 -0
index 880d745..a2d8700 100644
@@ -229,7 +229,7 @@ void one_measurement(int seconds, char *workload)
 
Quoted 6 lines

src/main.cpp void one_measurement(int seconds, char *workload)

Quoted 6 lines
src/main.cpp +0 -1
 void out_of_memory()
 {
 
 	reset_display();
 
-	sprintf("%s...\n",_("PowerTOP is out of memory. PowerTOP is 

Aborting"));

Quoted 22 lines
Quoted 9 lines
src/main.cpp +1 -0
+	printf("%s...\n",_("PowerTOP is out of memory. PowerTOP is Aborting"));
src/main.cpp +0 -0
 	abort();
 
 }
@@ -458,7 +458,7 @@ int main(int argc, char **argv)
 
 #ifndef DISABLE_NCURSES

src/main.cpp int main(int argc, char **argv) · line 464

Quoted 10 lines
src/main.cpp +1 -1
 
 	endwin();
 
 #endif
 
-	sprintf("%s\n", _("Leaving PowerTOP"));
+	printf("%s\n", _("Leaving PowerTOP"));
 
 	end_process_data();
 	clear_process_data();

Oh, good catch!

Quoted 6 lines
Quoted 2 lines

Looks like changes were introduced by commit
8fd54ace0a398cd155bf0af620c85d0105778f6a.

That commit contains more abuse of sprintf:
https://github.com/fenrus75/powertop/commit/8fd54ace0a398cd155bf0af620c85d0105778f6a#L1L102
Writing to a constant string is not going to work, eh?

Yes, lots of sprintf abuse there but most of it is fixed in other patches. I think these are the only ones left.

/MF

#5 lore raw
In reply to Magnus Fromreide

patch accepted thank you.

Quoted 29 lines · Magnus Fromreide

This undos the last printf->sprintf change from 8fd54ace.

Signed-off-by Magnus Fromreide<magfr(a)lysator.liu.se>
---
  src/main.cpp |    4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
src/main.cpp +2 -2
index 880d745..a2d8700 100644
@@ -229,7 +229,7 @@ void one_measurement(int seconds, char *workload)
  void out_of_memory()
  {
  	reset_display();
-	sprintf("%s...\n",_("PowerTOP is out of memory. PowerTOP is Aborting"));
+	printf("%s...\n",_("PowerTOP is out of memory. PowerTOP is Aborting"));
  	abort();
  }
 
@@ -458,7 +458,7 @@ int main(int argc, char **argv)
  #ifndef DISABLE_NCURSES
  	endwin();
  #endif
-	sprintf("%s\n", _("Leaving PowerTOP"));
+	printf("%s\n", _("Leaving PowerTOP"));
 
  	end_process_data();
  	clear_process_data();