summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGreg Ercolano <erco@seriss.com>2014-10-27 19:47:12 +0000
committerGreg Ercolano <erco@seriss.com>2014-10-27 19:47:12 +0000
commit78127ffdd5e3a10f7a33abc1a7648f34d1d8102d (patch)
treeb9eff2be9f4ce99cee86fbb4456bf470448ba923 /src
parent954ea00079cb2792489f94e6bd50a0096b8444a9 (diff)
Internally manage alloc'ed copy of linenumber_format().
(As per Alrecht's comment #9 in STR #2621) git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10396 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/Fl_Text_Display.cxx18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/Fl_Text_Display.cxx b/src/Fl_Text_Display.cxx
index 0923aa2ff..f6c3f50c2 100644
--- a/src/Fl_Text_Display.cxx
+++ b/src/Fl_Text_Display.cxx
@@ -25,6 +25,7 @@
#include "flstring.h"
#include <limits.h>
#include <ctype.h>
+#include <string.h> // strdup()
#include <FL/Fl.H>
#include <FL/Fl_Text_Buffer.H>
#include <FL/Fl_Text_Display.H>
@@ -158,7 +159,7 @@ Fl_Text_Display::Fl_Text_Display(int X, int Y, int W, int H, const char* l)
linenumber_fgcolor_ = FL_INACTIVE_COLOR;
linenumber_bgcolor_ = 53; // ~90% gray
linenumber_align_ = FL_ALIGN_RIGHT;
- linenumber_format_ = "%d";
+ linenumber_format_ = strdup("%d");
#endif
}
@@ -180,6 +181,10 @@ Fl_Text_Display::~Fl_Text_Display() {
mBuffer->remove_predelete_callback(buffer_predelete_cb, this);
}
if (mLineStarts) delete[] mLineStarts;
+ if (linenumber_format_) {
+ free((void*)linenumber_format_);
+ linenumber_format_ = 0;
+ }
}
@@ -321,7 +326,13 @@ Fl_Align Fl_Text_Display::linenumber_align() const {
/**
Sets the printf() style format string used for line numbers.
- Default is "%d" for normal unpadded decimal integers. Example values:
+ Default is "%d" for normal unpadded decimal integers.
+
+ An internal copy of \p val is allocated and managed;
+ it is automatically freed whenever a new value is assigned,
+ or when the widget is destroyed.
+
+ Example values:
- "%d" -- For normal line numbers without padding (Default)
- "%03d" -- For 000 padding
@@ -332,7 +343,8 @@ Fl_Align Fl_Text_Display::linenumber_align() const {
*/
void Fl_Text_Display::linenumber_format(const char* val) {
#if FLTK_ABI_VERSION >= 10303
- linenumber_format_ = val;
+ if ( linenumber_format_ ) free((void*)linenumber_format_);
+ linenumber_format_ = val ? strdup(val) : 0;
#else
// do nothing
#endif