summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorExplorer09 <explorer09@gmail.com>2022-04-20 13:05:35 +0800
committerBenBE <BenBE@geshi.org>2022-05-30 07:50:32 +0200
commit9ed9d73ab548ef81328c97686f4b01dee107392e (patch)
treee020db81ae8c6f703fd5203d177b8c5a1e6a7280
parent999801464a8a4d818e2ee3c87855a66929538a62 (diff)
Correct titleBuffer size and share it in alignedProcessFieldTitle()
* The size of titleBuffer should be 257 bytes, not 256. * Remove redundant `static char titleBuffer[]` delarations within `alignedProcessFieldTitle()` and let the subroutine use one shared buffer for printing field title. This reduces code size. Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
-rw-r--r--ProcessList.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/ProcessList.c b/ProcessList.c
index 705786f6..fcc77a5f 100644
--- a/ProcessList.c
+++ b/ProcessList.c
@@ -82,40 +82,41 @@ void ProcessList_setPanel(ProcessList* this, Panel* panel) {
this->panel = panel;
}
-static const char* alignedDynamicColumnTitle(const ProcessList* this, int key) {
+static const char* alignedDynamicColumnTitle(const ProcessList* this, int key, char* titleBuffer, size_t titleBufferSize) {
const DynamicColumn* column = Hashtable_get(this->dynamicColumns, key);
if (column == NULL)
return "- ";
- static char titleBuffer[DYNAMIC_MAX_COLUMN_WIDTH + /* space */ 1 + /* null terminator */ + 1];
int width = column->width;
if (!width || abs(width) > DYNAMIC_MAX_COLUMN_WIDTH)
width = DYNAMIC_DEFAULT_COLUMN_WIDTH;
- xSnprintf(titleBuffer, sizeof(titleBuffer), "%*s", width, column->heading);
+ xSnprintf(titleBuffer, titleBufferSize, "%*s", width, column->heading);
return titleBuffer;
}
static const char* alignedProcessFieldTitle(const ProcessList* this, ProcessField field) {
+ static char titleBuffer[UINT8_MAX + sizeof(" ")];
+ assert(sizeof(titleBuffer) >= DYNAMIC_MAX_COLUMN_WIDTH + sizeof(" "));
+ assert(sizeof(titleBuffer) >= PROCESS_MAX_PID_DIGITS + sizeof(" "));
+ assert(sizeof(titleBuffer) >= PROCESS_MAX_UID_DIGITS + sizeof(" "));
+
if (field >= LAST_PROCESSFIELD)
- return alignedDynamicColumnTitle(this, field);
+ return alignedDynamicColumnTitle(this, field, titleBuffer, sizeof(titleBuffer));
const char* title = Process_fields[field].title;
if (!title)
return "- ";
if (Process_fields[field].pidColumn) {
- static char titleBuffer[PROCESS_MAX_PID_DIGITS + sizeof(" ")];
xSnprintf(titleBuffer, sizeof(titleBuffer), "%*s ", Process_pidDigits, title);
return titleBuffer;
}
if (field == ST_UID) {
- static char titleBuffer[PROCESS_MAX_UID_DIGITS + sizeof(" ")];
xSnprintf(titleBuffer, sizeof(titleBuffer), "%*s ", Process_uidDigits, title);
return titleBuffer;
}
if (Process_fields[field].autoWidth) {
- static char titleBuffer[UINT8_MAX + 1];
if (field == PERCENT_CPU)
xSnprintf(titleBuffer, sizeof(titleBuffer), "%*s ", Process_fieldWidths[field], title);
else

© 2014-2024 Faster IT GmbH | imprint | privacy policy