From 2da6629e0f42e2ba32ed523d1bb55ee39f69aa0d Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Mon, 28 May 2018 10:04:23 +0200 Subject: [PATCH] Problem: Magic numbers "1" and "100" in signaler.cpp Solution: introduced constants, use std::min/std::max instead of control structures --- src/signaler.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/signaler.cpp b/src/signaler.cpp index 07ede6f0..0c4e609d 100644 --- a/src/signaler.cpp +++ b/src/signaler.cpp @@ -99,11 +99,10 @@ static int sleep_ms (unsigned int ms_) static int close_wait_ms (int fd_, unsigned int max_ms_ = 2000) { unsigned int ms_so_far = 0; - unsigned int step_ms = max_ms_ / 10; - if (step_ms < 1) - step_ms = 1; - if (step_ms > 100) - step_ms = 100; + const unsigned int min_step_ms = 1; + const unsigned int max_step_ms = 100; + const unsigned int step_ms = + std::min (std::max (min_step_ms, max_ms_ / 10), max_step_ms); int rc = 0; // do not sleep on first attempt do {