From: Martin Schwenke Date: Sat, 30 Jul 2022 00:19:56 +0000 (+1000) Subject: ctdb-common: CID 1507498: Control flow issues (DEADCODE) X-Git-Tag: samba-4.17.0rc1~155 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3aecd6e7b501abfd2c65f8d006a67001f79dd5fc;p=thirdparty%2Fsamba.git ctdb-common: CID 1507498: Control flow issues (DEADCODE) Fix typo in error checking. While here adjust the bottom of the range, making errno 0 invalid. Add corresponding test cases using an alternative syntax for errno packets (#nnn[;] - trailing ';' is optional). Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs Autobuild-User(master): Amitay Isaacs Autobuild-Date(master): Mon Aug 1 09:19:55 UTC 2022 on sn-devel-184 --- diff --git a/ctdb/common/tmon.c b/ctdb/common/tmon.c index 87a55e3b1e9..04bad1f3bf4 100644 --- a/ctdb/common/tmon.c +++ b/ctdb/common/tmon.c @@ -97,7 +97,7 @@ bool tmon_set_exit(struct tmon_pkt *pkt) bool tmon_set_errno(struct tmon_pkt *pkt, int err) { - if (err < 0 && err > UINT16_MAX) { + if (err <= 0 || err > UINT16_MAX) { return false; } diff --git a/ctdb/tests/UNIT/cunit/tmon_test_002.sh b/ctdb/tests/UNIT/cunit/tmon_test_002.sh index 97a17a188e5..e4118a3d09a 100755 --- a/ctdb/tests/UNIT/cunit/tmon_test_002.sh +++ b/ctdb/tests/UNIT/cunit/tmon_test_002.sh @@ -4,6 +4,7 @@ epipe=$(errcode EPIPE) etimedout=$(errcode ETIMEDOUT) +edom=$(errcode EDOM) test_cases() { @@ -35,6 +36,34 @@ WRITER OK EOF unit_test tmon_test "7" false 0 false + test_case "errno 110 packet @ 1s, no timeout" + ok <write_data[state->offset]; + err = (int)strtol(t, &end, 10); + state->offset += (end - t); + if (state->write_data[state->offset] == ';') { + state->offset++; + } + status = tmon_set_errno(pkt, err); + break; default: status = false; }