Skip to content

Commit

Permalink
Use struct member to determine size of allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
BenBE committed Apr 20, 2024
1 parent 784ef08 commit 6f14269
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Header.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ void Header_writeBackToSettings(const Header* this) {
const Vector* vec = this->columns[col];
int len = Vector_size(vec);

colSettings->names = len ? xCalloc(len + 1, sizeof(char*)) : NULL;
colSettings->modes = len ? xCalloc(len, sizeof(MeterModeId)) : NULL;
colSettings->names = len ? xCalloc(len + 1, sizeof(*colSettings->names)) : NULL;
colSettings->modes = len ? xCalloc(len, sizeof(*colSettings->modes)) : NULL;
colSettings->len = len;

for (int i = 0; i < len; i++) {
Expand Down
4 changes: 2 additions & 2 deletions Settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ static void Settings_defaultMeters(Settings* this, unsigned int initialCpuCount)
this->hLayout = HF_TWO_50_50;
this->hColumns = xCalloc(HeaderLayout_getColumns(this->hLayout), sizeof(MeterColumnSetting));
for (size_t i = 0; i < 2; i++) {
this->hColumns[i].names = xCalloc(sizes[i] + 1, sizeof(char*));
this->hColumns[i].modes = xCalloc(sizes[i], sizeof(MeterModeId));
this->hColumns[i].names = xCalloc(sizes[i] + 1, sizeof(*this->hColumns[0].names));
this->hColumns[i].modes = xCalloc(sizes[i], sizeof(*this->hColumns[0].modes));
this->hColumns[i].len = sizes[i];
}

Expand Down

0 comments on commit 6f14269

Please sign in to comment.