Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/rtadvd Lack of timeout is a programming error, so u...



details:   https://anonhg.NetBSD.org/src/rev/1844bb7d4b0c
branches:  trunk
changeset: 322162:1844bb7d4b0c
user:      roy <roy%NetBSD.org@localhost>
date:      Fri Apr 20 16:07:48 2018 +0000

description:
Lack of timeout is a programming error, so use an assert in it's place.
While here, improve the error reported if malloc fails.

diffstat:

 usr.sbin/rtadvd/timer.c |  13 +++++--------
 1 files changed, 5 insertions(+), 8 deletions(-)

diffs (40 lines):

diff -r 4696903343d5 -r 1844bb7d4b0c usr.sbin/rtadvd/timer.c
--- a/usr.sbin/rtadvd/timer.c   Fri Apr 20 15:59:17 2018 +0000
+++ b/usr.sbin/rtadvd/timer.c   Fri Apr 20 16:07:48 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: timer.c,v 1.17 2018/04/20 15:59:17 roy Exp $   */
+/*     $NetBSD: timer.c,v 1.18 2018/04/20 16:07:48 roy Exp $   */
 /*     $KAME: timer.c,v 1.11 2005/04/14 06:22:35 suz Exp $     */
 
 /*
@@ -33,6 +33,7 @@
 #include <sys/queue.h>
 #include <sys/time.h>
 
+#include <assert.h>
 #include <limits.h>
 #include <unistd.h>
 #include <syslog.h>
@@ -63,19 +64,15 @@
 {
        struct rtadvd_timer *newtimer;
 
+       assert(timeout != NULL);
+
        if ((newtimer = malloc(sizeof(*newtimer))) == NULL) {
-               logit(LOG_ERR,
-                      "<%s> can't allocate memory", __func__);
+               logit(LOG_ERR, "%s: malloc: %m", __func__);
                exit(EXIT_FAILURE);
        }
 
        memset(newtimer, 0, sizeof(*newtimer));
 
-       if (timeout == NULL) {
-               logit(LOG_ERR,
-                      "<%s> timeout function unspecified", __func__);
-               exit(EXIT_FAILURE);
-       }
        newtimer->expire = timeout;
        newtimer->update = update;
        newtimer->expire_data = timeodata;



Home | Main Index | Thread Index | Old Index