From 960ff1572f16c5e038342a566e91533711577cfb Mon Sep 17 00:00:00 2001 From: Andrew Wood Date: Sun, 27 Jul 2025 00:31:45 +0100 Subject: [PATCH] Pass state->status, rather than state itself, to pv_format (#165). --- src/include/pv-internal.h | 2 +- src/pv/display.c | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/include/pv-internal.h b/src/include/pv-internal.h index 7955144..53c247d 100644 --- a/src/include/pv-internal.h +++ b/src/include/pv-internal.h @@ -559,7 +559,7 @@ pvdisplay_bytecount_t pv_formatter_previous_line(pvformatter_args_t); pvdisplay_bytecount_t pv_formatter_name(pvformatter_args_t); pvdisplay_bytecount_t pv_formatter_sgr(pvformatter_args_t); -bool pv_format(pvstate_t, pvcontrol_t, readonly_pvtransferstate_t, readonly_pvtransfercalc_t, /*@null@*/ const char *, pvdisplay_t, bool, bool); +bool pv_format(pvprogramstatus_t, pvcontrol_t, readonly_pvtransferstate_t, readonly_pvtransfercalc_t, /*@null@*/ const char *, pvdisplay_t, bool, bool); void pv_display(pvstate_t, bool); ssize_t pv_transfer(pvstate_t, int, bool *, bool *, off_t, long *); int pv_next_file(pvstate_t, unsigned int, int); diff --git a/src/pv/display.c b/src/pv/display.c index 453ea54..93c6307 100644 --- a/src/pv/display.c +++ b/src/pv/display.c @@ -946,7 +946,7 @@ static void pv__format_init(pvcontrol_t control, readonly_pvtransferstate_t tran /* * Update display->display_buffer with status information formatted - * according to the state held within the given structure. + * according to the state held within the given structures. * * If "reinitialise" is true, the format string is reparsed first. This * should be true for the first call, and true whenever the format is @@ -961,9 +961,11 @@ static void pv__format_init(pvcontrol_t control, readonly_pvtransferstate_t tran * display->display_string_len to the length of the string in * display->display_buffer, in bytes. * + * Updates status->exit_status if buffer allocation fails. + * * See pv__format_init for the adjustments that may be made to "control". */ -bool pv_format(pvstate_t state, pvcontrol_t control, readonly_pvtransferstate_t transfer, +bool pv_format(pvprogramstatus_t status, pvcontrol_t control, readonly_pvtransferstate_t transfer, readonly_pvtransfercalc_t calc, /*@null@ */ const char *format_supplied, pvdisplay_t display, bool reinitialise, bool final) { @@ -1042,7 +1044,7 @@ bool pv_format(pvstate_t state, pvcontrol_t control, readonly_pvtransferstate_t new_buffer = malloc(new_size + 16); if (NULL == new_buffer) { pv_error("%s: %s", _("buffer allocation failed"), strerror(errno)); - state->status.exit_status |= PV_ERROREXIT_MEMORY; + status->exit_status |= PV_ERROREXIT_MEMORY; display->display_buffer = NULL; return false; } @@ -1268,14 +1270,14 @@ void pv_display(pvstate_t state, bool final) } if (!pv_format - (state, &(state->control), &(state->transfer), &(state->calc), state->control.format_string, + (&(state->status), &(state->control), &(state->transfer), &(state->calc), state->control.format_string, &(state->display), reinitialise, final)) return; if (0 != state->control.extra_displays) { if (!pv_format - (state, &(state->control), &(state->transfer), &(state->calc), state->control.extra_format_string, - &(state->extra_display), reinitialise, final)) + (&(state->status), &(state->control), &(state->transfer), &(state->calc), + state->control.extra_format_string, &(state->extra_display), reinitialise, final)) return; }