summaryrefslogtreecommitdiffstats
path: root/dmi.c
diff options
context:
space:
mode:
Diffstat (limited to 'dmi.c')
-rw-r--r--dmi.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/dmi.c b/dmi.c
index b927994..1a59834 100644
--- a/dmi.c
+++ b/dmi.c
@@ -109,6 +109,7 @@ static struct criteria criteria_from_dmidecode(void) {
char buf[BUF_SIZE];
struct criteria r = {0, NULL};
+ size_t allocated = MAX_DEVICES;
if (!(f = dmidecode_file ? fopen(dmidecode_file, "r") : popen("dmidecode", "r"))) {
perror("dmidecode");
@@ -142,6 +143,10 @@ static struct criteria criteria_from_dmidecode(void) {
char *s = buf + tab_level + 1;
char *val = get_after_colon(s);
if (val && lookup_field(category, s)) {
+ if (r.nb >= allocated) {
+ allocated = r.nb*2;
+ r.criteria = realloc(r.criteria, sizeof(struct criterion) * allocated);
+ }
struct criterion *criterion = &r.criteria[r.nb++];
asprintf(&criterion->name, "%s/%s", category->cat_name, s);
remove_ending_spaces(val);
@@ -179,6 +184,7 @@ static struct dmi_entries entries_matching_criteria(struct criteria criteria) {
enum state { in_constraints, in_implies } state = in_implies;
int was_a_blank_line = 1;
+ size_t allocated = MAX_DEVICES;
r.nb = 0;
f = fh_open("dmitable");
@@ -210,6 +216,10 @@ static struct dmi_entries entries_matching_criteria(struct criteria criteria) {
was_a_blank_line = 0;
if (valid[refine]) {
+ if (r.nb >= allocated) {
+ allocated = r.nb*2;
+ r.entries = realloc(r.entries, sizeof(struct criterion) * allocated);
+ }
struct dmi_entry *entry = &r.entries[r.nb++];
s += strlen("=> ");