From: ratchov Date: Fri, 29 Jan 2021 11:25:05 +0000 (+0000) Subject: Order opt_list in opt_new() call order, limit items to OPT_NMAX X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=869641a98e63d5087aa35c83f1a44c857395e351;p=openbsd Order opt_list in opt_new() call order, limit items to OPT_NMAX No behavior change, except for improved debug printfs. --- diff --git a/usr.bin/sndiod/opt.c b/usr.bin/sndiod/opt.c index aff4bb2f573..9e7a221f3d5 100644 --- a/usr.bin/sndiod/opt.c +++ b/usr.bin/sndiod/opt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: opt.c,v 1.5 2021/01/29 11:21:00 ratchov Exp $ */ +/* $OpenBSD: opt.c,v 1.6 2021/01/29 11:25:05 ratchov Exp $ */ /* * Copyright (c) 2008-2011 Alexandre Ratchov * @@ -30,17 +30,10 @@ opt_new(struct dev *d, char *name, int pmin, int pmax, int rmin, int rmax, int maxweight, int mmc, int dup, unsigned int mode) { - struct opt *o; - unsigned int len; + struct opt *o, **po; + unsigned int len, num; char c; - if (opt_byname(d, name)) { - dev_log(d); - log_puts("."); - log_puts(name); - log_puts(": already defined\n"); - return NULL; - } for (len = 0; name[len] != '\0'; len++) { if (len == OPT_NAMEMAX) { log_puts(name); @@ -55,7 +48,23 @@ opt_new(struct dev *d, char *name, return NULL; } } + num = 0; + for (po = &opt_list; *po != NULL; po = &(*po)->next) + num++; + if (num >= OPT_NMAX) { + log_puts(name); + log_puts(": too many opts\n"); + return NULL; + } + if (opt_byname(d, name)) { + dev_log(d); + log_puts("."); + log_puts(name); + log_puts(": already defined\n"); + return NULL; + } o = xmalloc(sizeof(struct opt)); + o->num = num; o->dev = d; if (mode & MODE_PLAY) { o->pmin = pmin; @@ -70,8 +79,8 @@ opt_new(struct dev *d, char *name, o->dup = dup; o->mode = mode; memcpy(o->name, name, len + 1); - o->next = opt_list; - opt_list = o; + o->next = *po; + *po = o; if (log_level >= 2) { dev_log(d); log_puts("."); diff --git a/usr.bin/sndiod/opt.h b/usr.bin/sndiod/opt.h index 9c12639aec5..b9737f8ea34 100644 --- a/usr.bin/sndiod/opt.h +++ b/usr.bin/sndiod/opt.h @@ -1,4 +1,4 @@ -/* $OpenBSD: opt.h,v 1.3 2021/01/29 11:21:00 ratchov Exp $ */ +/* $OpenBSD: opt.h,v 1.4 2021/01/29 11:25:05 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov * @@ -17,11 +17,14 @@ #ifndef OPT_H #define OPT_H +#define OPT_NMAX 16 + struct dev; struct opt { struct opt *next; struct dev *dev; + int num; #define OPT_NAMEMAX 11 char name[OPT_NAMEMAX + 1]; int maxweight; /* max dynamic range for clients */