Skip to content

Commit f4bd894

Browse files
natoscottBenBE
authored andcommitted
Merge branch 'replace-xmalloc-with-xasprintf' of kingmidas-hack/htop
2 parents 53f7e63 + 842a050 commit f4bd894

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

pcp/PCPDynamicColumn.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ static bool PCPDynamicColumn_addMetric(PCPDynamicColumns* columns, PCPDynamicCol
3636
if (!column->super.name[0])
3737
return false;
3838

39-
size_t bytes = 16 + strlen(column->super.name);
40-
char* metricName = xMalloc(bytes);
41-
xSnprintf(metricName, bytes, "htop.column.%s", column->super.name);
39+
char* metricName = NULL;
40+
xAsprintf(&metricName, "htop.column.%s", column->super.name);
4241

4342
column->metricName = metricName;
4443
column->id = columns->offset + columns->cursor;

pcp/PCPDynamicMeter.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ in the source distribution for its full text.
3030

3131

3232
static PCPDynamicMetric* PCPDynamicMeter_lookupMetric(PCPDynamicMeters* meters, PCPDynamicMeter* meter, const char* name) {
33-
size_t bytes = 16 + strlen(meter->super.name) + strlen(name);
34-
char* metricName = xMalloc(bytes);
35-
xSnprintf(metricName, bytes, "htop.meter.%s.%s", meter->super.name, name);
33+
char* metricName = NULL;
34+
xAsprintf(&metricName, "htop.meter.%s.%s", meter->super.name, name);
3635

3736
PCPDynamicMetric* metric;
3837
for (size_t i = 0; i < meter->totalMetrics; i++) {

pcp/PCPDynamicScreen.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,11 @@ static void PCPDynamicScreens_appendDynamicColumns(PCPDynamicScreens* screens, P
7171

7272
static PCPDynamicColumn* PCPDynamicScreen_lookupMetric(PCPDynamicScreen* screen, const char* name) {
7373
PCPDynamicColumn* column = NULL;
74-
size_t bytes = strlen(name) + strlen(screen->super.name) + 1; /* colon */
75-
if (bytes >= sizeof(column->super.name))
74+
if ((strlen(name) + strlen(screen->super.name) + 1) >= sizeof(column->super.name)) /* colon */
7675
return NULL;
7776

78-
bytes += 16; /* prefix, dots and terminator */
79-
char* metricName = xMalloc(bytes);
80-
xSnprintf(metricName, bytes, "htop.screen.%s.%s", screen->super.name, name);
77+
char* metricName = NULL;
78+
xAsprintf(&metricName, "htop.screen.%s.%s", screen->super.name, name);
8179

8280
for (size_t i = 0; i < screen->totalColumns; i++) {
8381
column = screen->columns[i];

0 commit comments

Comments
 (0)