summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Melcher <github@matthiasm.com>2022-12-22 00:18:01 +0100
committerGitHub <noreply@github.com>2022-12-22 00:18:01 +0100
commitd98c6638938b09934889b5c639a56d4dea10a6fb (patch)
tree58bd129f6e21535a483e995ac3325264c8ec1347
parent1d212b7a0394fb72e76b3e713e2aa949cea4d612 (diff)
Fix compilation on old gcc (#606)
* Fixing char* use in FLUID * Fixing const cast
-rw-r--r--FL/Fl_String.H4
-rw-r--r--fluid/code.cxx2
-rw-r--r--fluid/fluid.cxx13
-rw-r--r--fluid/fluid.h2
-rw-r--r--src/Fl_JPEG_Image.cxx2
-rw-r--r--src/Fl_String.cxx25
6 files changed, 36 insertions, 12 deletions
diff --git a/FL/Fl_String.H b/FL/Fl_String.H
index 300cf98f6..4a20c48b2 100644
--- a/FL/Fl_String.H
+++ b/FL/Fl_String.H
@@ -91,7 +91,7 @@ public:
private:
void init();
- void alloc_buf(int size);
+ void alloc_buf(int size, bool preserve_text=false);
void release();
public:
@@ -99,10 +99,12 @@ public:
void value(const char *str, int slen);
const char *value() const { return value_; }
+ char *buffer() { return value_; }
int size() const { return size_; }
int slen() const;
int capacity() const;
+ void capacity(int num_bytes);
void debug(const char *info = 0) const; // output string info
void hexdump(const char *info = 0) const; // output string info + hexdump
diff --git a/fluid/code.cxx b/fluid/code.cxx
index 52625b8e7..5cc02a241 100644
--- a/fluid/code.cxx
+++ b/fluid/code.cxx
@@ -612,7 +612,7 @@ int write_code(const char *s, const char *t) {
write_c("// Initialize I18N stuff now for menus...\n");
write_c("#%sinclude <locale.h>\n", indent());
write_c("static char *_locale = setlocale(LC_MESSAGES, \"\");\n");
- write_c("static nl_catd _catalog = catopen(\"%s\", 0);\n", P.i18n_program);
+ write_c("static nl_catd _catalog = catopen(\"%s\", 0);\n", P.i18n_program.value());
}
}
if (conditional) {
diff --git a/fluid/fluid.cxx b/fluid/fluid.cxx
index 8aaf8f6b1..38a74dec1 100644
--- a/fluid/fluid.cxx
+++ b/fluid/fluid.cxx
@@ -254,7 +254,6 @@ Project P;
Project::Project() :
i18n_type(0),
- i18n_program(""),
include_H_from_C(1),
use_FL_COMMAND(0),
utf8_in_src(0),
@@ -277,7 +276,7 @@ void Project::reset() {
i18n_static_function = "";
i18n_file = "";
i18n_set = "";
- i18n_program[0] = 0;
+ i18n_program = "";
include_H_from_C = 1;
use_FL_COMMAND = 0;
utf8_in_src = 0;
@@ -998,8 +997,9 @@ int write_code_files() {
}
char cname[FL_PATH_MAX+1];
char hname[FL_PATH_MAX+1];
- strlcpy(P.i18n_program, fl_filename_name(filename), FL_PATH_MAX);
- fl_filename_setext(P.i18n_program, FL_PATH_MAX, "");
+ P.i18n_program = fl_filename_name(filename);
+ P.i18n_program.capacity(FL_PATH_MAX);
+ fl_filename_setext(P.i18n_program.buffer(), FL_PATH_MAX, "");
if (P.code_file_name[0] == '.' && strchr(P.code_file_name, '/') == NULL) {
strlcpy(cname, fl_filename_name(filename), FL_PATH_MAX);
fl_filename_setext(cname, FL_PATH_MAX, P.code_file_name);
@@ -1878,8 +1878,9 @@ void update_sourceview_cb(Fl_Button*, void*)
sv_strings->buffer()->loadfile(fn);
sv_strings->scroll(top, 0);
} else if (sv_source->visible_r() || sv_header->visible_r()) {
- strlcpy(P.i18n_program, fl_filename_name(sv_source_filename), FL_PATH_MAX);
- fl_filename_setext(P.i18n_program, FL_PATH_MAX, "");
+ P.i18n_program = fl_filename_name(sv_source_filename);
+ P.i18n_program.capacity(FL_PATH_MAX);
+ fl_filename_setext(P.i18n_program.buffer(), FL_PATH_MAX, "");
Fd_String code_file_name_bak = P.code_file_name;
P.code_file_name = sv_source_filename;
Fd_String header_file_name_bak = P.header_file_name;
diff --git a/fluid/fluid.h b/fluid/fluid.h
index 98ed1886d..52ba75ba2 100644
--- a/fluid/fluid.h
+++ b/fluid/fluid.h
@@ -105,7 +105,7 @@ public:
Fd_String i18n_static_function;
Fd_String i18n_file;
Fd_String i18n_set;
- char i18n_program[FL_PATH_MAX+1];
+ Fd_String i18n_program;
int include_H_from_C;
int use_FL_COMMAND;
int utf8_in_src;
diff --git a/src/Fl_JPEG_Image.cxx b/src/Fl_JPEG_Image.cxx
index e8e32c6db..b20bcf133 100644
--- a/src/Fl_JPEG_Image.cxx
+++ b/src/Fl_JPEG_Image.cxx
@@ -304,7 +304,7 @@ void Fl_JPEG_Image::load_jpg_(const char *filename, const char *sharename, const
if (data_length==-1)
jpeg_unprotected_mem_src(&dinfo, data);
else
- jpeg_mem_src(&dinfo, data, (size_t)data_length);
+ jpeg_mem_src(&dinfo, const_cast<unsigned char*>data, (size_t)data_length);
}
jpeg_read_header(&dinfo, TRUE);
diff --git a/src/Fl_String.cxx b/src/Fl_String.cxx
index 380493b21..59f7ace64 100644
--- a/src/Fl_String.cxx
+++ b/src/Fl_String.cxx
@@ -69,7 +69,12 @@ Fl_String::~Fl_String() {
delete[] value_;
}
-void Fl_String::alloc_buf(int size) {
+/** Grow the buffer size to at least size+1 bytes.
+ By default, this call destroys the contents of the current buffer.
+ \param size in bytes
+ \param preserve_text copy existing text into the new buffer
+ */
+void Fl_String::alloc_buf(int size, bool preserve_text) {
if (size < 0)
return;
if (size > 0 && size <= capacity_)
@@ -79,7 +84,14 @@ void Fl_String::alloc_buf(int size) {
char *new_value = new char[new_size];
capacity_ = new_size - 1;
- size_ = 0;
+ if (preserve_text) {
+ size_ = (int)strlen(value_);
+ // the new buffer always has a higher capacity than the old one
+ // make sure we copy the trailing NUL.
+ memcpy(new_value, value_, size_+1);
+ } else {
+ size_ = 0;
+ }
delete[] value_;
value_ = new_value;
}
@@ -111,6 +123,15 @@ int Fl_String::capacity() const {
return capacity_; // > 0 ? capacity_ - 1 : capacity_;
}
+/** Set the minumum capacity to num_bytes plus one for a terminating NUL.
+ The cintents of the string buffer will be copied if needed.
+ \param num_bytes minimum size of buffer
+ */
+void Fl_String::capacity(int num_bytes) {
+ alloc_buf(num_bytes, true);
+}
+
+
void Fl_String::release() {
delete[] value_;
value_ = 0;