[{"id":13420,"web_url":"https://patchwork.libcamera.org/comment/13420/","msgid":"<20201022150647.GE3938@pendragon.ideasonboard.com>","date":"2020-10-22T15:06:47","subject":"Re: [libcamera-devel] [PATCH 4/4] HACK: suppress clang-tidy warnings","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Tomi,\n\nThank you for the patch.\n\nOn Thu, Oct 22, 2020 at 11:17:31AM +0300, Tomi Valkeinen wrote:\n> These are quick hacks to silence clang-tidy warnings. The purpose of\n> this patch is just to highlight the warnings on the mailing list, and\n> also, if you want to try to fix some of the warnings, it may be nice to\n> have all the rest suppressed.\n> \n> Afaics, the thread->moveObject(this) warning is a false positive.\n> Probably some of the others are too.\n> \n> Note that I used assert() there in a few places, just after ASSERT().\n> The reason being, ASSERT() just prints an error, while assert() aborts,\n> so clang-tidy takes the assert() seriously.\n\nLOG(Fatal) aborts too. Could this be fixed with annotate ASSERT() with\n[[noreturn]] ? Something along the lines of (untested)\n\ndiff --git a/include/libcamera/internal/log.h b/include/libcamera/internal/log.h\nindex 4b10087a4718..a9fc5526a971 100644\n--- a/include/libcamera/internal/log.h\n+++ b/include/libcamera/internal/log.h\n@@ -117,9 +117,14 @@ LogMessage _log(const char *file, unsigned int line,\n #endif /* __DOXYGEN__ */\n\n #ifndef NDEBUG\n+static inline [[noreturn]] void _assert(const char *message)\n+{\n+\tLOG(Fatal) << message;\n+}\n+\n #define ASSERT(condition) static_cast<void>(({\t\t\t\t\\\n \tif (!(condition))\t\t\t\t\t\t\\\n-\t\tLOG(Fatal) << \"assertion \\\"\" #condition \"\\\" failed\";\t\\\n+\t\t_assert(\"assertion \\\"\" #condition \"\\\" failed\");\t\t\\\n }))\n #else\n #define ASSERT(condition) static_cast<void>(false && (condition))\n\n> Not for merging.\n> \n> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@iki.fi>\n> ---\n>  src/ipa/raspberrypi/controller/histogram.cpp       | 2 +-\n>  src/libcamera/object.cpp                           | 3 ++-\n>  src/libcamera/pipeline/ipu3/ipu3.cpp               | 1 +\n>  src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 2 ++\n>  src/libcamera/pipeline/rkisp1/rkisp1.cpp           | 2 ++\n>  src/libcamera/v4l2_device.cpp                      | 1 -\n>  src/libcamera/v4l2_pixelformat.cpp                 | 2 +-\n>  7 files changed, 9 insertions(+), 4 deletions(-)\n> \n> diff --git a/src/ipa/raspberrypi/controller/histogram.cpp b/src/ipa/raspberrypi/controller/histogram.cpp\n> index 9916b3ed..ac3f5c48 100644\n> --- a/src/ipa/raspberrypi/controller/histogram.cpp\n> +++ b/src/ipa/raspberrypi/controller/histogram.cpp\n> @@ -51,7 +51,7 @@ double Histogram::InterQuantileMean(double q_lo, double q_hi) const\n>  \tdouble p_lo = Quantile(q_lo);\n>  \tdouble p_hi = Quantile(q_hi, (int)p_lo);\n>  \tdouble sum_bin_freq = 0, cumul_freq = 0;\n> -\tfor (double p_next = floor(p_lo) + 1.0; p_next <= ceil(p_hi);\n> +\tfor (double p_next = floor(p_lo) + 1.0; p_next <= ceil(p_hi); // NOLINT: Variable 'p_next' with floating point type 'double' should not be used as a loop counter [clang-analyzer-security.FloatLoopCounter]\n>  \t     p_lo = p_next, p_next += 1.0) {\n>  \t\tint bin = floor(p_lo);\n>  \t\tdouble freq = (cumulative_[bin + 1] - cumulative_[bin]) *\n> diff --git a/src/libcamera/object.cpp b/src/libcamera/object.cpp\n> index cd83c684..1b1775e6 100644\n> --- a/src/libcamera/object.cpp\n> +++ b/src/libcamera/object.cpp\n> @@ -257,7 +257,8 @@ void Object::moveToThread(Thread *thread)\n>  \n>  \tnotifyThreadMove();\n>  \n> -\tthread->moveObject(this);\n> +\t// clang-tidy thinks that the thread can be deleted via DeferredDelete handling in notifyThreadMove()\n\nThe thread, or 'this' object ? It seems to be a false positive in any\ncase.\n\n> +\tthread->moveObject(this); // NOLINT: warning: Use of memory after it is freed [clang-analyzer-cplusplus.NewDelete]\n>  }\n>  \n>  void Object::notifyThreadMove()\n> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> index af47739d..eac27153 100644\n> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> @@ -508,6 +508,7 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c)\n>  \t * be at least one active stream in the configuration request).\n>  \t */\n>  \tif (!vfCfg) {\n> +\t\tassert(mainCfg);\n>  \t\tret = imgu->configureViewfinder(*mainCfg, &outputFormat);\n>  \t\tif (ret)\n>  \t\t\treturn ret;\n> diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> index aa8d9340..4544d606 100644\n> --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> @@ -1290,6 +1290,7 @@ void RPiCameraData::unicamBufferDequeue(FrameBuffer *buffer)\n>  \n>  \t/* The buffer must belong to one of our streams. */\n>  \tASSERT(stream);\n> +\tassert(stream);\n>  \n>  \tLOG(RPI, Debug) << \"Stream \" << stream->name() << \" buffer dequeue\"\n>  \t\t\t<< \", buffer id \" << index\n> @@ -1358,6 +1359,7 @@ void RPiCameraData::ispOutputDequeue(FrameBuffer *buffer)\n>  \n>  \t/* The buffer must belong to one of our ISP output streams. */\n>  \tASSERT(stream);\n> +\tassert(stream);\n>  \n>  \tLOG(RPI, Debug) << \"Stream \" << stream->name() << \" buffer complete\"\n>  \t\t\t<< \", buffer id \" << index\n> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> index c74a2e9b..be55c32f 100644\n> --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> @@ -379,6 +379,8 @@ protected:\n>  \t\tif (!info)\n>  \t\t\tLOG(RkISP1, Fatal) << \"Frame not known\";\n\nThis could be replace by ASSERT().\n\n>  \n> +\t\tassert(info);\n> +\n>  \t\t/*\n>  \t\t * \\todo: If parameters are not filled a better method to handle\n>  \t\t * the situation than queuing a buffer with unknown content\n> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\n> index 31d4dad0..f747ba79 100644\n> --- a/src/libcamera/v4l2_device.cpp\n> +++ b/src/libcamera/v4l2_device.cpp\n> @@ -243,7 +243,6 @@ ControlList V4L2Device::getControls(const std::vector<uint32_t> &ids)\n>  \t\tLOG(V4L2, Error) << \"Unable to read control \" << errorIdx\n>  \t\t\t\t << \": \" << strerror(-ret);\n>  \t\tcount = errorIdx - 1;\n> -\t\tret = errorIdx;\n\nThis could indeed be dropped.\n\n>  \t}\n>  \n>  \tupdateControls(&ctrls, v4l2Ctrls, count);\n> diff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp\n> index 03ab085c..354136b7 100644\n> --- a/src/libcamera/v4l2_pixelformat.cpp\n> +++ b/src/libcamera/v4l2_pixelformat.cpp\n> @@ -163,7 +163,7 @@ std::string V4L2PixelFormat::toString() const\n>  \t}\n>  \n>  \tif (fourcc_ & (1 << 31))\n> -\t\tstrcat(ss, \"-BE\");\n> +\t\tmemcpy(ss + 4, \"-BE\", 3);\n\nWhat bug does this fix ?\n\n>  \n>  \treturn ss;\n>  }","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 55944C3D3C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 22 Oct 2020 15:07:35 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CC40B61426;\n\tThu, 22 Oct 2020 17:07:34 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id CCA74610B6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 22 Oct 2020 17:07:33 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 3947353;\n\tThu, 22 Oct 2020 17:07:33 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"UcLAltNW\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1603379253;\n\tbh=VR57xcPLgRuFVbGzE3omoLgrq/VgqZJS+hjfEC9ou2g=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=UcLAltNW5yiu+jue87wOL4WY5JN1ddaNy3Wz7NCJ0SjBIZEJmKQoibjlma0LzbKKn\n\t4DwReqj6Wu/FHkohz7d18a2KVAAOLF9rJD/ayX1Kdd/avOmvGSfDvWjuwyMm8nKJAK\n\t6QUySlwM12anBzGhI0fm6Oa4zg9+w0dd96spewsI=","Date":"Thu, 22 Oct 2020 18:06:47 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Tomi Valkeinen <tomi.valkeinen@iki.fi>","Message-ID":"<20201022150647.GE3938@pendragon.ideasonboard.com>","References":"<20201022081731.36217-1-tomi.valkeinen@iki.fi>\n\t<20201022081731.36217-4-tomi.valkeinen@iki.fi>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20201022081731.36217-4-tomi.valkeinen@iki.fi>","Subject":"Re: [libcamera-devel] [PATCH 4/4] HACK: suppress clang-tidy warnings","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]