system: fix undefined behavior in wdt offline check
authorAlexander Couzens <lynxis@fe80.eu>
Wed, 23 Sep 2015 13:04:18 +0000 (15:04 +0200)
committerJohn Crispin <blogic@openwrt.org>
Sat, 3 Oct 2015 07:47:35 +0000 (09:47 +0200)
watchdog_fd() is returning a char* and not a int. checking against < 0 could
lead in undefined behaviour.

Signed-off-by: Alexander Couzens <lynxis@fe80.eu>
system.c

index 82c672ee4900eb65a93bac1e9e587c0e76c9c8dc..fb7fbe48cbd945f694d373faf6c74f186a67dd69 100644 (file)
--- a/system.c
+++ b/system.c
@@ -282,7 +282,7 @@ static int watchdog_set(struct ubus_context *ctx, struct ubus_object *obj,
        if (tb[WDT_STOP])
                watchdog_set_stopped(blobmsg_get_bool(tb[WDT_STOP]));
 
-       if (watchdog_fd() < 0)
+       if (watchdog_fd() == NULL)
                status = "offline";
        else if (watchdog_get_stopped())
                status = "stopped";