diff --git a/pcp/PCPDynamicColumn.c b/pcp/PCPDynamicColumn.c index b2ebe985a..6ea7d5108 100644 --- a/pcp/PCPDynamicColumn.c +++ b/pcp/PCPDynamicColumn.c @@ -36,9 +36,8 @@ static bool PCPDynamicColumn_addMetric(PCPDynamicColumns* columns, PCPDynamicCol if (!column->super.name[0]) return false; - size_t bytes = 16 + strlen(column->super.name); - char* metricName = xMalloc(bytes); - xSnprintf(metricName, bytes, "htop.column.%s", column->super.name); + char* metricName = NULL; + xAsprintf(&metricName, "htop.column.%s", column->super.name); column->metricName = metricName; column->id = columns->offset + columns->cursor; diff --git a/pcp/PCPDynamicMeter.c b/pcp/PCPDynamicMeter.c index 5fe96ae4d..311f1af52 100644 --- a/pcp/PCPDynamicMeter.c +++ b/pcp/PCPDynamicMeter.c @@ -30,9 +30,8 @@ in the source distribution for its full text. static PCPDynamicMetric* PCPDynamicMeter_lookupMetric(PCPDynamicMeters* meters, PCPDynamicMeter* meter, const char* name) { - size_t bytes = 16 + strlen(meter->super.name) + strlen(name); - char* metricName = xMalloc(bytes); - xSnprintf(metricName, bytes, "htop.meter.%s.%s", meter->super.name, name); + char* metricName = NULL; + xAsprintf(&metricName, "htop.meter.%s.%s", meter->super.name, name); PCPDynamicMetric* metric; for (size_t i = 0; i < meter->totalMetrics; i++) { diff --git a/pcp/PCPDynamicScreen.c b/pcp/PCPDynamicScreen.c index 281722fac..84d3a7cc7 100644 --- a/pcp/PCPDynamicScreen.c +++ b/pcp/PCPDynamicScreen.c @@ -71,13 +71,11 @@ static void PCPDynamicScreens_appendDynamicColumns(PCPDynamicScreens* screens, P static PCPDynamicColumn* PCPDynamicScreen_lookupMetric(PCPDynamicScreen* screen, const char* name) { PCPDynamicColumn* column = NULL; - size_t bytes = strlen(name) + strlen(screen->super.name) + 1; /* colon */ - if (bytes >= sizeof(column->super.name)) + if ((strlen(name) + strlen(screen->super.name) + 1) >= sizeof(column->super.name)) /* colon */ return NULL; - bytes += 16; /* prefix, dots and terminator */ - char* metricName = xMalloc(bytes); - xSnprintf(metricName, bytes, "htop.screen.%s.%s", screen->super.name, name); + char* metricName = NULL; + xAsprintf(&metricName, "htop.screen.%s.%s", screen->super.name, name); for (size_t i = 0; i < screen->totalColumns; i++) { column = screen->columns[i];