Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/midirecord avoid assert() and simply return errors.
details: https://anonhg.NetBSD.org/src/rev/930ee61b55e6
branches: trunk
changeset: 354093:930ee61b55e6
user: mrg <mrg%NetBSD.org@localhost>
date: Sat Jun 03 21:31:14 2017 +0000
description:
avoid assert() and simply return errors.
diffstat:
usr.bin/midirecord/midirecord.c | 43 ++++++++++++++++++++++++++++++----------
1 files changed, 32 insertions(+), 11 deletions(-)
diffs (105 lines):
diff -r 4569d8276b80 -r 930ee61b55e6 usr.bin/midirecord/midirecord.c
--- a/usr.bin/midirecord/midirecord.c Sat Jun 03 21:28:48 2017 +0000
+++ b/usr.bin/midirecord/midirecord.c Sat Jun 03 21:31:14 2017 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: midirecord.c,v 1.11 2016/12/11 08:40:10 mrg Exp $ */
+/* $NetBSD: midirecord.c,v 1.12 2017/06/03 21:31:14 mrg Exp $ */
/*
- * Copyright (c) 2014, 2015 Matthew R. Green
+ * Copyright (c) 2014, 2015, 2017 Matthew R. Green
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -33,7 +33,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: midirecord.c,v 1.11 2016/12/11 08:40:10 mrg Exp $");
+__RCSID("$NetBSD: midirecord.c,v 1.12 2017/06/03 21:31:14 mrg Exp $");
#endif
#include <sys/param.h>
@@ -53,7 +53,6 @@
#include <string.h>
#include <unistd.h>
#include <util.h>
-#include <assert.h>
#include <stdbool.h>
#include "libaudio.h"
@@ -327,6 +326,11 @@
unsigned val = 0, xdiv;
int vallen = 0, i;
+ if (bufsize < 4) {
+ warnx("too small bufsize: %zu", bufsize);
+ return 0;
+ }
+
if (prev_div == 0 && !oflag)
prev_div = e.t_WAIT_ABS.divisions;
cur_div = e.t_WAIT_ABS.divisions;
@@ -415,9 +419,18 @@
{
size_t size = 0;
- assert(e.common.channel < 16);
LOG("SEQ_CHN_COMMON");
+ if (bufsize < 3) {
+ warnx("too small bufsize: %zu", bufsize);
+ return 0;
+ }
+
+ if (e.common.channel >= 16) {
+ warnx("invalid channel: %u", e.common.channel);
+ return 0;
+ }
+
if (filter_devchan(e.common.device, e.common.channel))
return 0;
@@ -474,9 +487,18 @@
{
size_t size = 0;
- assert(e.common.channel < 16);
LOG("SEQ_CHN_VOICE");
+ if (bufsize < 3) {
+ warnx("too small bufsize: %zu", bufsize);
+ return 0;
+ }
+
+ if (e.common.channel >= 16) {
+ warnx("invalid channel: %u", e.common.channel);
+ return 0;
+ }
+
if (filter_devchan(e.voice.device, e.voice.channel))
return 0;
@@ -554,9 +576,6 @@
{
size_t size = 0;
- /* XXX so far we only process 4 byte returns */
- assert(bufsize >= 4);
-
LOG("event: %02x:%02x:%02x:%02x %02x:%02x:%02x:%02x", e.tag,
e.unknown.byte[0], e.unknown.byte[1],
e.unknown.byte[2], e.unknown.byte[3],
@@ -716,8 +735,10 @@
err(1, "failed to stop midi timer");
}
- close(outfd);
- close(midifd);
+ if (close(outfd) != 0)
+ warn("couldn't close output");
+ if (close(midifd) != 0)
+ warn("couldn't close midi device");
if (signo != 0)
(void)raise_default_signal(signo);
Home |
Main Index |
Thread Index |
Old Index