{"id":26670,"url":"https://patchwork.libcamera.org/api/patches/26670/?format=json","web_url":"https://patchwork.libcamera.org/patch/26670/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260507112321.22726-1-drneildmatthews@googlemail.com>","date":"2026-05-07T11:23:16","name":"Fix some issues highlighted by static checking","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"d27af0ab407969356b6e9ca690648a6f3f064cd1","submitter":{"id":272,"url":"https://patchwork.libcamera.org/api/people/272/?format=json","name":"Neil Matthews","email":"drneildmatthews@googlemail.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/26670/mbox/","series":[],"comments":"https://patchwork.libcamera.org/api/patches/26670/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/26670/checks/","tags":{},"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 166CDBE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  7 May 2026 11:23:32 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3766062FE1;\n\tThu,  7 May 2026 13:23:31 +0200 (CEST)","from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com\n\t[IPv6:2a00:1450:4864:20::32d])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8D90962010\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  7 May 2026 13:23:29 +0200 (CEST)","by mail-wm1-x32d.google.com with SMTP id\n\t5b1f17b1804b1-48d146705b4so9064605e9.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 07 May 2026 04:23:29 -0700 (PDT)","from neilmatthews-Precision-3571.home\n\t(host86-132-133-211.range86-132.btcentralplus.com. [86.132.133.211])\n\tby smtp.gmail.com with ESMTPSA id\n\t5b1f17b1804b1-48e538d222esm136064935e9.14.2026.05.07.04.23.28\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 07 May 2026 04:23:28 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=googlemail.com header.i=@googlemail.com\n\theader.b=\"IxuvpeA1\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=googlemail.com; s=20251104; t=1778153009; x=1778757809;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:mime-version:message-id:date:subject:cc\n\t:to:from:from:to:cc:subject:date:message-id:reply-to;\n\tbh=Or3DggdgmHTOtunvwpf3FTEvLseaEwpGUBzEA0qK6RA=;\n\tb=IxuvpeA1Ml/dpR4li0wg3Fw3gvf0Q+L2jz7/yMAxXG8+pOyBEAJZJHqwLA0gmR5oxW\n\tsTXxyhzzpnge7CpuQBY46GdwgiauxEPz2qRgJ7DJ4NPMUI2C/aCGg5qDt1tRxMRDt1Hf\n\tNrpQq13uM4RB002wCTBCeyentYX566Fl8PVb8Qi5+WbyzL2txRSwb8MOUcwU4nJI1JMS\n\tXUGMjzfyFj327EZU4ggRfT97fzoBnaVxW47h816BXFWcr3rmBpe2ccPbDAhvDcej9MWQ\n\tEm5lqe8y/acudNye/tY91g8iMdKZPitFper+0bf1XKDOrEteII3MPH68VadGHKBDweZ8\n\tu6zA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20251104; t=1778153009; x=1778757809;\n\th=content-transfer-encoding:mime-version:message-id:date:subject:cc\n\t:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date\n\t: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o+0AYlGAABqqck6LjXgKQ6arhdNMWt5tm+C5\n\tPjRNgXoqxAk+BMZh9ShwqlEPPrGq0phDDE7QqkyT5gmXBACScleAzel4A51","X-Received":"by 2002:a05:600d:10:b0:488:e7e4:8425 with SMTP id\n\t5b1f17b1804b1-48e51f4ea40mr102278705e9.23.1778153008751; \n\tThu, 07 May 2026 04:23:28 -0700 (PDT)","From":"Neil Matthews <drneildmatthews@googlemail.com>","To":"","Cc":"libcamera-devel@lists.libcamera.org,\n\tNeil Matthews <drneildmatthews@googlemail.com>","Subject":"Fix some issues highlighted by static checking","Date":"Thu,  7 May 2026 12:23:16 +0100","Message-ID":"<20260507112321.22726-1-drneildmatthews@googlemail.com>","X-Mailer":"git-send-email 2.43.0","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Dear All,\nFirst submission -- apologies if not following established procedures.\nCompiles, but untested.\n\nThere may be better solutions to the enum versus flag changes.\n\nBest regards,\nNeil Matthews\n\nFrom a1f071f276612e97ab29c27dc6fb5bf62d0599f0 Mon Sep 17 00:00:00 2001\nFrom: Neil Matthews <drneildmatthews@googlemail.com>\nDate: Fri, 1 May 2026 16:46:30 +0100\nSubject: [PATCH] Fix some issues highlighted by static checking.\n\nCheckers were invoked as:\n\ncppcheck --enable=all --force --inconclusive\n\nand as\n\nbear ninja -C build\nfind . -name \"*.cpp\" -exec clang-tidy {} ';'\n\nIssues raised include:\n- using enums as flags that are or'ed together creating values not defined in the enum\n- checking result of malloc\n- checking (null) pointers before dereferencing\n- avoiding strcat()\n\nOther flagged issues remain to be reviewed and fixed if required.\n\nSigned-off-by: Neil Matthews <drneildmatthews@googlemail.com>\n---\n include/libcamera/base/memfd.h                 |  1 +\n include/libcamera/controls.h                   |  1 +\n include/libcamera/internal/dma_buf_allocator.h |  2 ++\n src/android/metadata/camera_metadata.c         |  4 ++++\n src/libcamera/base/object.cpp                  |  3 +++\n src/libcamera/ipa_data_serializer.cpp          | 16 ++++++++++++----\n src/libcamera/pipeline/ipu3/ipu3.cpp           |  4 +---\n src/libcamera/pipeline/simple/simple.cpp       |  3 +++\n src/libcamera/software_isp/debayer_cpu.cpp     |  2 --\n src/libcamera/v4l2_pixelformat.cpp             |  7 ++++---\n 10 files changed, 31 insertions(+), 12 deletions(-)","diff":"diff --git a/include/libcamera/base/memfd.h b/include/libcamera/base/memfd.h\nindex 5ffa0f22..6805d374 100644\n--- a/include/libcamera/base/memfd.h\n+++ b/include/libcamera/base/memfd.h\n@@ -21,6 +21,7 @@ public:\n \t\tNone = 0,\n \t\tShrink = (1 << 0),\n \t\tGrow = (1 << 1),\n+                ShrinkAndGrow = Shrink | Grow,\n \t};\n \n \tusing Seals = Flags<Seal>;\ndiff --git a/include/libcamera/controls.h b/include/libcamera/controls.h\nindex 44ff4964..a22fe28f 100644\n--- a/include/libcamera/controls.h\n+++ b/include/libcamera/controls.h\n@@ -253,6 +253,7 @@ public:\n \tenum class Direction {\n \t\tIn = (1 << 0),\n \t\tOut = (1 << 1),\n+                InAndOut = In | Out,\n \t};\n \n \tusing DirectionFlags = Flags<Direction>;\ndiff --git a/include/libcamera/internal/dma_buf_allocator.h b/include/libcamera/internal/dma_buf_allocator.h\nindex 13600915..40dc36da 100644\n--- a/include/libcamera/internal/dma_buf_allocator.h\n+++ b/include/libcamera/internal/dma_buf_allocator.h\n@@ -26,7 +26,9 @@ public:\n \tenum class DmaBufAllocatorFlag {\n \t\tCmaHeap = 1 << 0,\n \t\tSystemHeap = 1 << 1,\n+\t\tCmaHeapAndSystemHeap = CmaHeap | SystemHeap,\n \t\tUDmaBuf = 1 << 2,\n+\t\tCmaHeapAndSystemHeapAndUDmaBuf = CmaHeap | SystemHeap | UDmaBuf,\n \t};\n \n \tusing DmaBufAllocatorFlags = Flags<DmaBufAllocatorFlag>;\ndiff --git a/src/android/metadata/camera_metadata.c b/src/android/metadata/camera_metadata.c\nindex b86586a7..89cc792f 100644\n--- a/src/android/metadata/camera_metadata.c\n+++ b/src/android/metadata/camera_metadata.c\n@@ -242,6 +242,10 @@ camera_metadata_t *allocate_copy_camera_metadata_checked(\n     }\n \n     void *buffer = malloc(src_size);\n+    if(!buffer) {\n+        return NULL;\n+    }\n+\n     memcpy(buffer, src, src_size);\n \n     camera_metadata_t *metadata = (camera_metadata_t*) buffer;\ndiff --git a/src/libcamera/base/object.cpp b/src/libcamera/base/object.cpp\nindex 37d133cc..6f075560 100644\n--- a/src/libcamera/base/object.cpp\n+++ b/src/libcamera/base/object.cpp\n@@ -207,6 +207,9 @@ void Object::message(Message *msg)\n \t\t * it in release mode (with -O2 or -O3).\n \t\t */\n \t\tInvokeMessage *iMsg = dynamic_cast<InvokeMessage *>(msg);\n+                if(!iMsg)\n+                        break;\n+\n \t\tSemaphore *semaphore = iMsg->semaphore();\n \t\tiMsg->invoke();\n \ndiff --git a/src/libcamera/ipa_data_serializer.cpp b/src/libcamera/ipa_data_serializer.cpp\nindex 0537f785..86698684 100644\n--- a/src/libcamera/ipa_data_serializer.cpp\n+++ b/src/libcamera/ipa_data_serializer.cpp\n@@ -311,9 +311,11 @@ template<>\n std::tuple<std::vector<uint8_t>, std::vector<SharedFD>>\n IPADataSerializer<ControlList>::serialize(const ControlList &data, ControlSerializer *cs)\n {\n-\tif (!cs)\n+\tif (!cs) {\n \t\tLOG(IPADataSerializer, Fatal)\n \t\t\t<< \"ControlSerializer not provided for serialization of ControlList\";\n+\t\treturn {};\n+        }\n \n \tsize_t size;\n \tstd::vector<uint8_t> infoData;\n@@ -361,9 +363,11 @@ IPADataSerializer<ControlList>::deserialize(std::vector<uint8_t>::const_iterator\n \t\t\t\t\t    std::vector<uint8_t>::const_iterator dataEnd,\n \t\t\t\t\t    ControlSerializer *cs)\n {\n-\tif (!cs)\n+\tif (!cs) {\n \t\tLOG(IPADataSerializer, Fatal)\n \t\t\t<< \"ControlSerializer not provided for deserialization of ControlList\";\n+\t\treturn {};\n+        }\n \n \tif (std::distance(dataBegin, dataEnd) < 8)\n \t\treturn {};\n@@ -436,9 +440,11 @@ std::tuple<std::vector<uint8_t>, std::vector<SharedFD>>\n IPADataSerializer<ControlInfoMap>::serialize(const ControlInfoMap &map,\n \t\t\t\t\t     ControlSerializer *cs)\n {\n-\tif (!cs)\n+\tif (!cs) {\n \t\tLOG(IPADataSerializer, Fatal)\n \t\t\t<< \"ControlSerializer not provided for serialization of ControlInfoMap\";\n+\t\treturn {};\n+        }\n \n \tsize_t size = cs->binarySize(map);\n \tstd::vector<uint8_t> infoData(size);\n@@ -463,9 +469,11 @@ IPADataSerializer<ControlInfoMap>::deserialize(std::vector<uint8_t>::const_itera\n \t\t\t\t\t       std::vector<uint8_t>::const_iterator dataEnd,\n \t\t\t\t\t       ControlSerializer *cs)\n {\n-\tif (!cs)\n+\tif (!cs) {\n \t\tLOG(IPADataSerializer, Fatal)\n \t\t\t<< \"ControlSerializer not provided for deserialization of ControlInfoMap\";\n+\t\treturn {};\n+        }\n \n \tif (std::distance(dataBegin, dataEnd) < 4)\n \t\treturn {};\ndiff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex bf4c2921..15f918cd 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -565,7 +565,6 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c)\n \n \t/* Apply the format to the configured streams output devices. */\n \tStreamConfiguration *mainCfg = nullptr;\n-\tStreamConfiguration *vfCfg = nullptr;\n \n \tfor (unsigned int i = 0; i < config->size(); ++i) {\n \t\tStreamConfiguration &cfg = (*config)[i];\n@@ -577,7 +576,6 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c)\n \t\t\tif (ret)\n \t\t\t\treturn ret;\n \t\t} else if (stream == vfStream) {\n-\t\t\tvfCfg = &cfg;\n \t\t\tret = imgu->configureViewfinder(cfg, &outputFormat);\n \t\t\tif (ret)\n \t\t\t\treturn ret;\n@@ -589,7 +587,7 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c)\n \t * the configuration of the active one for that purpose (there should\n \t * be at least one active stream in the configuration request).\n \t */\n-\tif (!vfCfg) {\n+\tif (mainCfg) {\n \t\tret = imgu->configureViewfinder(*mainCfg, &outputFormat);\n \t\tif (ret)\n \t\t\treturn ret;\ndiff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp\nindex c6fe12d6..3a5f9095 100644\n--- a/src/libcamera/pipeline/simple/simple.cpp\n+++ b/src/libcamera/pipeline/simple/simple.cpp\n@@ -985,6 +985,9 @@ void SimpleCameraData::clearIncompleteRequests()\n \n void SimpleCameraData::tryCompleteRequest(Request *request)\n {\n+        if (!request)\n+                return;\n+\n \tif (request->hasPendingBuffers())\n \t\treturn;\n \ndiff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp\nindex d9f5b326..1b89a721 100644\n--- a/src/libcamera/software_isp/debayer_cpu.cpp\n+++ b/src/libcamera/software_isp/debayer_cpu.cpp\n@@ -820,8 +820,6 @@ void DebayerCpuThread::process2(uint32_t frame, const uint8_t *src, uint8_t *dst\n \t\t/* next line may point outside of src, use prev. */\n \t\tlinePointers[2] = linePointers[0];\n \t\tdebayer_->debayer1(dst, linePointers);\n-\t\tsrc += inputStride;\n-\t\tdst += outputStride;\n \t}\n }\n \ndiff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp\nindex e8b3eb9c..105f5bed 100644\n--- a/src/libcamera/v4l2_pixelformat.cpp\n+++ b/src/libcamera/v4l2_pixelformat.cpp\n@@ -291,15 +291,16 @@ std::string V4L2PixelFormat::toString() const\n \tchar ss[8] = { static_cast<char>(fourcc_ & 0x7f),\n \t\t       static_cast<char>((fourcc_ >> 8) & 0x7f),\n \t\t       static_cast<char>((fourcc_ >> 16) & 0x7f),\n-\t\t       static_cast<char>((fourcc_ >> 24) & 0x7f) };\n+\t\t       static_cast<char>((fourcc_ >> 24) & 0x7f),\n+                       '-', 'B', 'E', 0 };\n \n \tfor (unsigned int i = 0; i < 4; i++) {\n \t\tif (!isprint(ss[i]))\n \t\t\tss[i] = '.';\n \t}\n \n-\tif (fourcc_ & (1 << 31))\n-\t\tstrcat(ss, \"-BE\");\n+\tif (!(fourcc_ & (1 << 31)))\n+\t\tss[4] = 0;\n \n \treturn ss;\n }\n","prefixes":[]}