diff options
| author | Matthias Melcher <github@matthiasm.com> | 2022-12-22 00:18:01 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-22 00:18:01 +0100 |
| commit | d98c6638938b09934889b5c639a56d4dea10a6fb (patch) | |
| tree | 58bd129f6e21535a483e995ac3325264c8ec1347 /src | |
| parent | 1d212b7a0394fb72e76b3e713e2aa949cea4d612 (diff) | |
Fix compilation on old gcc (#606)
* Fixing char* use in FLUID
* Fixing const cast
Diffstat (limited to 'src')
| -rw-r--r-- | src/Fl_JPEG_Image.cxx | 2 | ||||
| -rw-r--r-- | src/Fl_String.cxx | 25 |
2 files changed, 24 insertions, 3 deletions
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; |
