if (r)
return r;
- unsigned int cols_left = cols - p->num_widgets - 2;
+ int cols_left = cols - p->num_widgets - 2;
// Count how many widgets we have processed
unsigned int widgets = 0;
}
}
- // How many expandable widgets are left?
- int num_expandables = p->num_widgets - widgets;
-
- // How much space do we allocate to each of them?
- int width = cols_left / num_expandables;
-
- // Process all expandable widgets
- STAILQ_FOREACH(widget, &p->widgets, nodes) {
- if (widget->expandable) {
- r = widget->print(p, widget, width, widget->data);
- if (r < 0)
- return r;
+ // Print the expendable stuff only if there is space left
+ if (cols_left > 0) {
+ // How many expandable widgets are left?
+ int num_expandables = p->num_widgets - widgets;
+
+ // How much space do we allocate to each of them?
+ int width = cols_left / num_expandables;
+
+ // Process all expandable widgets
+ STAILQ_FOREACH(widget, &p->widgets, nodes) {
+ if (widget->expandable) {
+ r = widget->print(p, widget, width, widget->data);
+ if (r < 0)
+ return r;
+ }
}
}
static ssize_t cli_progressbar_bar(struct cli_progressbar* p,
struct cli_progressbar_widget* widget, unsigned int width, void* data) {
+ // This only works if we have at least one byte to fill
+ if (!width)
+ return -ENOBUFS;
+
// Allocate or adjust the buffer
widget->buffer = pakfire_realloc(widget->buffer, width + 1);