From: sthen Date: Fri, 8 May 2015 12:15:50 +0000 (+0000) Subject: Separately track the number of items in alloc_table in a variable. With X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=f55524eab5c74260b4466be708768c5035583708;p=openbsd Separately track the number of items in alloc_table in a variable. With the changes for handling template files in r1.293, alloc_table became a pointer to an array of structs (rather than the array itself), so nitems(alloc_table) no longer returns the number of elements. As found by sebastia@, autosize would only try the first allocation scheme, so installation would fail on small disks. ok henning@ --- diff --git a/sbin/disklabel/editor.c b/sbin/disklabel/editor.c index 41ef9714072..83cc8a79aeb 100644 --- a/sbin/disklabel/editor.c +++ b/sbin/disklabel/editor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: editor.c,v 1.294 2015/04/29 16:46:39 henning Exp $ */ +/* $OpenBSD: editor.c,v 1.295 2015/05/08 12:15:50 sthen Exp $ */ /* * Copyright (c) 1997-2000 Todd C. Miller @@ -123,6 +123,7 @@ struct alloc_table alloc_table_default[] = { { alloc_stupid, nitems(alloc_stupid) } }; struct alloc_table *alloc_table = alloc_table_default; +int alloc_table_nitems = 4; void edit_parms(struct disklabel *); void editor_resize(struct disklabel *, char *); @@ -614,7 +615,7 @@ again: if (j == MAXPARTITIONS) { /* It did not work out, try next strategy */ free(alloc); - if (++index < nitems(alloc_table)) + if (++index < alloc_table_nitems) goto again; else return; @@ -677,7 +678,7 @@ cylinderalign: if (secs < ap->minsz) { /* It did not work out, try next strategy */ free(alloc); - if (++index < nitems(alloc_table)) + if (++index < alloc_table_nitems) goto again; else return; @@ -2385,6 +2386,7 @@ parse_autotable(char *filename) err(1, "%s", filename); if ((alloc_table = calloc(1, sizeof(struct alloc_table))) == NULL) err(1, NULL); + alloc_table_nitems = 1; while ((buf = fgetln(cfile, &len)) != NULL) { if ((alloc_table[0].table = reallocarray(alloc_table[0].table,