From 5bd10d1e439ed237d52bb650aafbdbd7b1daf75a Mon Sep 17 00:00:00 2001 From: Robin Roevens Date: Mon, 1 Apr 2019 08:37:52 +0200 Subject: [PATCH 1/2] Fix core dump on int2char call --- arduino/miflo/miflo.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arduino/miflo/miflo.ino b/arduino/miflo/miflo.ino index f17aa31..df26b9a 100644 --- a/arduino/miflo/miflo.ino +++ b/arduino/miflo/miflo.ino @@ -91,7 +91,7 @@ char* string2char(String s) { } char* int2char(int n) { - char s[16]; + static char s[16]; itoa(n, s, 10); return s; } From 856662b000f0f180b5ce648bc598cb358a1c007e Mon Sep 17 00:00:00 2001 From: Robin Roevens Date: Mon, 1 Apr 2019 08:39:25 +0200 Subject: [PATCH 2/2] Fix core dump on empty event task --- arduino/miflo/miflo.ino | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/arduino/miflo/miflo.ino b/arduino/miflo/miflo.ino index df26b9a..e36082d 100644 --- a/arduino/miflo/miflo.ino +++ b/arduino/miflo/miflo.ino @@ -84,10 +84,13 @@ bool todo_done[ 4 ] = { false, false, false, false }; char current_job_string[200] = ""; char* string2char(String s) { + static char *p; if (s.length() != 0) { - char *p = const_cast(s.c_str()); - return p; + p = const_cast(s.c_str()); + } else { + *p = 0; //empty string } + return p; } char* int2char(int n) { @@ -743,7 +746,7 @@ void show_upcoming_events() { int x = 0; for ( std::map::iterator i = cache.begin(); i != cache.end(); i++ ) { GD.cmd_text(20, 60 + x * 20, 20, 0, string2char( format_time( i->first / 10000, (i->first / 100) % 100, i->first % 100 ) ) ); - GD.cmd_text(80, 60 + x * 20, 20, 0, string2char(i->second)); + GD.cmd_text(80, 60 + x * 20, 20, 0, string2char( i->second )); x++; }