-/* $OpenBSD: editor.c,v 1.364 2021/01/31 14:18:44 naddy Exp $ */
+/* $OpenBSD: editor.c,v 1.365 2021/02/02 15:42:00 naddy Exp $ */
/*
* Copyright (c) 1997-2000 Todd C. Miller <millert@openbsd.org>
u_int64_t max_partition_size(struct disklabel *, int);
void display_edit(struct disklabel *, char);
void psize(u_int64_t sz, char unit, struct disklabel *lp);
-char *get_token(char **, size_t *);
+char *get_token(char **);
int apply_unit(double, u_char, u_int64_t *);
int parse_sizespec(const char *, double *, char **);
int parse_sizerange(char *, u_int64_t *, u_int64_t *);
parse_autotable(char *filename)
{
FILE *cfile;
- size_t len;
- char *buf, *t;
+ size_t bufsize = 0;
+ char *buf = NULL, *t;
uint idx = 0, pctsum = 0;
struct space_allocation *sa;
err(1, NULL);
alloc_table_nitems = 1;
- while ((buf = fgetln(cfile, &len)) != NULL) {
+ while (getline(&buf, &bufsize, cfile) != -1) {
if ((alloc_table[0].table = reallocarray(alloc_table[0].table,
idx + 1, sizeof(*sa))) == NULL)
err(1, NULL);
memset(sa, 0, sizeof(*sa));
idx++;
- if ((sa->mp = get_token(&buf, &len)) == NULL ||
+ if ((sa->mp = get_token(&buf)) == NULL ||
(sa->mp[0] != '/' && strcmp(sa->mp, "swap")))
errx(1, "%s: parse error on line %u", filename, idx);
- if ((t = get_token(&buf, &len)) == NULL ||
+ if ((t = get_token(&buf)) == NULL ||
parse_sizerange(t, &sa->minsz, &sa->maxsz) == -1)
errx(1, "%s: parse error on line %u", filename, idx);
- if ((t = get_token(&buf, &len)) != NULL &&
+ if ((t = get_token(&buf)) != NULL &&
parse_pct(t, &sa->rate) == -1)
errx(1, "%s: parse error on line %u", filename, idx);
if (sa->minsz > sa->maxsz)
if (pctsum > 100)
errx(1, "%s: sum of extra space allocation > 100%%", filename);
alloc_table[0].sz = idx;
+ free(buf);
fclose(cfile);
}
char *
-get_token(char **s, size_t *len)
+get_token(char **s)
{
char *p, *r;
size_t tlen = 0;
p = *s;
- while (*len > 0 && !isspace((u_char)**s)) {
+ while (**s != '\0' && !isspace((u_char)**s)) {
(*s)++;
- (*len)--;
tlen++;
}
if (tlen == 0)
return (NULL);
/* eat whitespace */
- while (*len > 0 && isspace((u_char)**s)) {
+ while (isspace((u_char)**s))
(*s)++;
- (*len)--;
- }
if ((r = strndup(p, tlen)) == NULL)
err(1, NULL);