Allocate more space for the display buffer, as wide characters take up more room.

This commit is contained in:
Andrew Wood
2024-12-13 20:38:45 +00:00
parent 9f5923864b
commit cb71277df4
2 changed files with 7 additions and 3 deletions
+1
View File
@@ -41,6 +41,7 @@ extern "C" {
#define PV_SIZEOF_LASTWRITTEN_BUFFER 256
#define PV_SIZEOF_PREVLINE_BUFFER 1024
#define PV_FORMAT_ARRAY_MAX 100
#define PV_SIZEOF_FORMAT_SEGMENTS_BUF 4096
#define PV_SIZEOF_CRS_LOCK_FILE 1024
#define PV_SIZEOF_FILE_FDINFO 4096
+6 -3
View File
@@ -849,7 +849,7 @@ bool pv_format(pvstate_t state, /*@null@ */ const char *format_supplied, pvdispl
bool final)
{
struct pvdisplay_component_s *format_component_array;
char display_segments[1024]; /* flawfinder: ignore - always bounded */
char display_segments[PV_SIZEOF_FORMAT_SEGMENTS_BUF]; /* flawfinder: ignore - always bounded */
size_t segment_idx, dynamic_segment_count;
const char *display_format;
size_t static_portion_width, dynamic_segment_width;
@@ -896,7 +896,7 @@ bool pv_format(pvstate_t state, /*@null@ */ const char *format_supplied, pvdispl
/*
* Reallocate the output buffer if the display width changes.
*/
if (display->display_buffer != NULL && display->display_buffer_size < (size_t) ((state->control.width * 2))) {
if (display->display_buffer != NULL && display->display_buffer_size < (size_t) ((state->control.width * 4))) {
free(display->display_buffer);
display->display_buffer = NULL;
display->display_buffer_size = 0;
@@ -909,7 +909,7 @@ bool pv_format(pvstate_t state, /*@null@ */ const char *format_supplied, pvdispl
char *new_buffer;
size_t new_size;
new_size = (size_t) ((2 * state->control.width) + 80);
new_size = (size_t) ((4 * state->control.width) + 80);
if (NULL != state->control.name)
new_size += strlen(state->control.name); /* flawfinder: ignore */
/* flawfinder: name is always set by pv_strdup(), which bounds with a \0. */
@@ -996,6 +996,9 @@ bool pv_format(pvstate_t state, /*@null@ */ const char *format_supplied, pvdispl
if (dynamic_segment_count > 1)
dynamic_segment_width /= dynamic_segment_count;
debug("control.width=%d static_portion_width=%d dynamic_segment_width=%d dynamic_segment_count=%d",
state->control.width, static_portion_width, dynamic_segment_width, dynamic_segment_count);
for (segment_idx = 0; segment_idx < display->format_segment_count; segment_idx++) {
pvdisplay_segment_t segment;
struct pvdisplay_component_s *component;