diff options
| author | Matthias Melcher <github@matthiasm.com> | 2024-12-04 14:22:15 +0100 |
|---|---|---|
| committer | Matthias Melcher <github@matthiasm.com> | 2024-12-04 14:22:21 +0100 |
| commit | 7d964d92aef46dab31a9d36cbeba1d5905e22430 (patch) | |
| tree | d892c8eb1e68e6731026b940d21fed74d4c31f6a | |
| parent | 8df4f8e398cffe69b2fa5fe2b608cfba72de9308 (diff) | |
FLUID: minor improvemnets to buffer handling (#1152)
The described crash can not be reproduced. The changes
improve the stability of the call that causes the crash.
| -rw-r--r-- | fluid/undo.cxx | 4 | ||||
| -rw-r--r-- | fluid/widget_browser.cxx | 27 |
2 files changed, 19 insertions, 12 deletions
diff --git a/fluid/undo.cxx b/fluid/undo.cxx index 67c800baa..3738d9d71 100644 --- a/fluid/undo.cxx +++ b/fluid/undo.cxx @@ -156,7 +156,7 @@ void undo_cb(Fl_Widget *, void *) { } } // Restore old browser position. - // Ideally, we would save the browser position insied the undo file. + // Ideally, we would save the browser position inside the undo file. if (widget_browser) widget_browser->restore_scroll_position(); undo_current --; @@ -178,7 +178,7 @@ void undo_checkpoint_once(int type) { undo_checkpoint(); undo_once_type = type; } else { - // do not add more checkpoints for the same undo typw + // do not add more checkpoints for the same undo type } } diff --git a/fluid/widget_browser.cxx b/fluid/widget_browser.cxx index 1540c6d75..d81c84f32 100644 --- a/fluid/widget_browser.cxx +++ b/fluid/widget_browser.cxx @@ -1,7 +1,7 @@ // // Widget Browser code for the Fast Light Tool Kit (FLTK). // -// Copyright 1998-2023 by Bill Spitzak and others. +// Copyright 1998-2024 by Bill Spitzak and others. // // This library is free software. Distribution and use rights are outlined in // the file "COPYING" which should have been included with this file. If this @@ -143,8 +143,8 @@ void reveal_in_browser(Fl_Type *t) { \param[out] p return the resulting string in this buffer, terminated with a NUL byte \param[in] str copy this string; utf8 aware - \param[in] maxl maximum number of letter to copy until we print - the elipsis (...) + \param[in] maxl maximum number of letters to copy until we print + the ellipsis (...) \param[in] quote if set, the resulting string is embedded in double quotes \param[in] trunc_lf if set, truncates at first newline \returns pointer to end of string (before terminating null byte). @@ -159,16 +159,23 @@ static char *copy_trunc(char *p, const char *str, int maxl, int quote, int trunc { int size = 0; // truncated string size in characters int bs; // size of UTF-8 character in bytes + if (!p) return NULL; // bad buffer + if (!str) { // no input string + if (quote) { *p++='"'; *p++='"'; } + *p = 0; + return p; + } const char *end = str + strlen(str); // end of input string if (quote) *p++ = '"'; // opening quote while (size < maxl) { // maximum <maxl> characters if (*str == '\n') { if (trunc_lf) { // handle trunc at \n - *p++ = 0; + if (quote) *p++ = '"'; // closing quote + *p = 0; return p; } *p++ = '\\'; *p++ = 'n'; - str++; size++; + str++; size+=2; continue; } if (!(*str & (-32))) break; // end of string (0 or control char) @@ -197,7 +204,7 @@ static char *copy_trunc(char *p, const char *str, int maxl, int quote, int trunc \param[in] X, Y, W, H position and size of widget \param[in] l optional label - \todo It would be nice to be able to grab one or more nodes and mmove them + \todo It would be nice to be able to grab one or more nodes and move them within the hierarchy. */ Widget_Browser::Widget_Browser(int X,int Y,int W,int H,const char*l) : @@ -305,7 +312,7 @@ void Widget_Browser::item_draw(void *v, int X, int Y, int, int) const { // cast to a more general type Fl_Type *l = (Fl_Type *)v; - char buf[340]; // edit buffer: large enough to hold 80 UTF-8 chars + nul + char buf[500]; // edit buffer: large enough to hold 80 UTF-8 chars + nul // calculate the horizontal start position of this item // 3 is the edge of the browser @@ -446,7 +453,7 @@ void Widget_Browser::item_draw(void *v, int X, int Y, int, int) const { */ int Widget_Browser::item_width(void *v) const { - char buf[340]; // edit buffer: large enough to hold 80 UTF-8 chars + nul + char buf[500]; // edit buffer: large enough to hold 80 UTF-8 chars + nul Fl_Type *l = (Fl_Type *)v; @@ -562,7 +569,7 @@ int Widget_Browser::handle(int e) { } /** - Save the current scrollbar postion during rebuild. + Save the current scrollbar position during rebuild. */ void Widget_Browser::save_scroll_position() { saved_h_scroll_ = hposition(); @@ -570,7 +577,7 @@ void Widget_Browser::save_scroll_position() { } /** - Restore the previous scrollbar postion after rebuild. + Restore the previous scrollbar position after rebuild. */ void Widget_Browser::restore_scroll_position() { hposition(saved_h_scroll_); |
