config: fix some glaring errors...
... like not properly initializing the config struct. Sigh.
This commit is contained in:
parent
6e9a68711d
commit
be27cccf45
35
src/config.c
35
src/config.c
|
@ -43,17 +43,17 @@ parse_config(char *path)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
conf = malloc(sizeof(config_t));
|
||||
conf = calloc(1, sizeof(config_t));
|
||||
if (conf == NULL) {
|
||||
perror("couldn't allocate config");
|
||||
return NULL;
|
||||
}
|
||||
memset(conf, 0, sizeof(config_t));
|
||||
|
||||
state = ST_FILENAME;
|
||||
line = col = 1;
|
||||
ws = comment = err = 0;
|
||||
i = 0;
|
||||
cur = conf;
|
||||
while ((ch = getc(fd)) != EOF) {
|
||||
switch (ch) {
|
||||
case '\t':
|
||||
|
@ -65,11 +65,16 @@ parse_config(char *path)
|
|||
/* only run on the first whitespace */
|
||||
if (!ws) {
|
||||
DPRINTF(("i = %d\n", i));
|
||||
i = 0;
|
||||
ws = 1;
|
||||
state++;
|
||||
DPRINTF(("%s:%d:%d: switching to state %d\n", path, line, col, state));
|
||||
switch (state) {
|
||||
switch (state-1) {
|
||||
case ST_FILENAME:
|
||||
cur->filename[i] = 0;
|
||||
break;
|
||||
case ST_EXT:
|
||||
cur->ext[i] = 0;
|
||||
break;
|
||||
/* convert offsets to uint32_t (or close enough) */
|
||||
case ST_START:
|
||||
cur->start = strtoul(ibuf, NULL, 10);
|
||||
|
@ -83,13 +88,8 @@ parse_config(char *path)
|
|||
case ST_SKIP_B:
|
||||
cur->skip_b = strtoul(ibuf, NULL, 10);
|
||||
break;
|
||||
/* parse options */
|
||||
case ST_OPTS:
|
||||
if (parse_conf_opts(&cur->opts, ibuf) != 0) {
|
||||
PMSG("error", "unable to parse opts (see above)");
|
||||
err = 1;
|
||||
}
|
||||
}
|
||||
i = 0;
|
||||
memset(ibuf, 0, 32);
|
||||
}
|
||||
break;
|
||||
|
@ -102,7 +102,7 @@ parse_config(char *path)
|
|||
* beginning of a line.
|
||||
*/
|
||||
if (state != ST_FILENAME || !comment) {
|
||||
cur->next = malloc(sizeof(config_t));
|
||||
cur->next = calloc(1, sizeof(config_t));
|
||||
if (cur == NULL) {
|
||||
perror("couldn't allocate config");
|
||||
err = 1;
|
||||
|
@ -113,9 +113,14 @@ parse_config(char *path)
|
|||
PMSG("error", "line ends early");
|
||||
err = 1;
|
||||
break;
|
||||
} else {
|
||||
DPRINTF(("filename: %s.%s\n", cur->filename, cur->ext));
|
||||
if (parse_conf_opts(&cur->opts, ibuf) != 0) {
|
||||
PMSG("error", "unable to parse opts (see above)");
|
||||
err = 1;
|
||||
}
|
||||
}
|
||||
|
||||
memset(cur->next, 0, sizeof(config_t));
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
|
@ -143,7 +148,6 @@ parse_config(char *path)
|
|||
err = 1;
|
||||
} else {
|
||||
cur->filename[i] = toupper(ch);
|
||||
DPRINTF(("%c", cur->filename[i]));
|
||||
i++;
|
||||
}
|
||||
break;
|
||||
|
@ -153,7 +157,6 @@ parse_config(char *path)
|
|||
err = 1;
|
||||
} else {
|
||||
cur->ext[i] = toupper(ch);
|
||||
DPRINTF(("%c", cur->ext[i]));
|
||||
i++;
|
||||
}
|
||||
break;
|
||||
|
@ -178,10 +181,10 @@ parse_config(char *path)
|
|||
}
|
||||
}
|
||||
|
||||
col++;
|
||||
|
||||
if (err)
|
||||
break;
|
||||
|
||||
col++;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue