Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 64D21C433FE for ; Wed, 23 Nov 2022 09:40:35 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6FBFA85563; Wed, 23 Nov 2022 10:40:32 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="EAWx8aJm"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B938C8554E; Wed, 23 Nov 2022 10:40:30 +0100 (CET) Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3D65C85061 for ; Wed, 23 Nov 2022 10:40:28 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilin.mikhail.ol@gmail.com Received: by mail-lj1-x230.google.com with SMTP id u2so20759068ljl.3 for ; Wed, 23 Nov 2022 01:40:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:references:references:in-reply-to:message-id:date :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=4gNVqU65n+OgvdLWodysbnGdSlxmaUz/nxjCx6oZjsY=; b=EAWx8aJm+kqI0Ma6TDxlrjzuWGGTOFDTY+SNJ3ZFA7Q60N+R/vbc2EyW2cxRMw45Wm ICW6CCsgrZLH+DjW45vpylyAWWyMHgvk2tt22XCuPhr/oABCOwwVaiAJLyIld19s8iUR kviRKGzF2uEXkgiU+gyJTV6RG1c6Pseu7IihrzhZcpJL0a8Nx9SR040yqYwwmO2BaMcg 95va40rWPs7/hNaPu9qRduAZIt7wsVzpg6DH/1V1Y6wf0lSSJMgTbzZYFAVTJlQLTYI1 zuCabZtdU1q8EXMYPvUz+5G2sKnzXjP49x4c7lSGGILk+gRR3W7ccoad3SmpvPXjpUps sN9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:references:references:in-reply-to:message-id:date :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=4gNVqU65n+OgvdLWodysbnGdSlxmaUz/nxjCx6oZjsY=; b=qppf591PQf0HPq40GeKA5rH7K40CIP0oalXYkK81epBOu2DyDs3+tblcvEonxEy0VJ swoBeUtzlfWpgdaXef8xG9msKDXS1kdm72g1pfc4TM5BRUaR764/LsXQxAwJss4s1zRb NKn/acgvNliI2HL/xf2E6vBGy2Ji6jOlpVA4XeIe6HfDauefsGHgsI0UOVjXACP+ITUs DsACWJabI70mZ4S3rb9Fik7urKgGTmbpODVb6FJE3PYCnlwwqJzkgN+zy0pqec4LM1/N /8abw1bLiFLcZZE0498lePA/GXslVpj9d7oA8sNMwZRpaTChD4KKDbsBHap2NmjaGV5p x4Fg== X-Gm-Message-State: ANoB5pkG0GFczhmdbqpToqh8YvIH6uFQGKcnzaU3jxixKvjKE4yuc0os BR88r6/rG+4VeTn+YGcxIBY= X-Google-Smtp-Source: AA0mqf7uqqId2QPEQ4NiYXaYqqWH8y8VGjC+kDX0Oqi9OMnbQH6SF+oiYlo7UKZsgXyz7orwFEkOnw== X-Received: by 2002:a05:651c:160a:b0:277:6e27:6000 with SMTP id f10-20020a05651c160a00b002776e276000mr8060577ljq.104.1669196427277; Wed, 23 Nov 2022 01:40:27 -0800 (PST) Received: from milin-wrk.rasu.local ([178.70.40.200]) by smtp.gmail.com with ESMTPSA id a24-20020ac25e78000000b0049adf925d00sm2833277lfr.1.2022.11.23.01.40.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 01:40:26 -0800 (PST) From: Mikhail Ilin To: Heinrich Schuchardt Cc: Mikhail Ilin , Simon Glass , u-boot@lists.denx.de Subject: [PATCH v3] tools: mkimage: Fix nullptr at strchr() Date: Wed, 23 Nov 2022 12:39:36 +0300 Message-Id: <20221123093936.19949-1-ilin.mikhail.ol@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: References: In-Reply-To: X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean The copy_datafile(ifd, params.datafile) function has been implemented to copy data by reducing the number of lines in the main function. Signed-off-by: Mikhail Ilin --- tools/mkimage.c | 35 +++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/tools/mkimage.c b/tools/mkimage.c index 30c6df7708..0b68a29285 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -430,6 +430,24 @@ static void verify_image(const struct image_type_params *tparams) (void)close(ifd); } +void copy_datafile(int ifd, char *file) +{ + if (!file) + return; + for (;;) { + char *sep = strchr(file, ':'); + + if (sep) { + *sep = '\0'; + copy_file(ifd, file, 1); + *sep++ = ':'; + file = sep; + } else { + copy_file(ifd, file, 0); + break; + } + } +} + int main(int argc, char **argv) { int ifd = -1; @@ -647,21 +666,7 @@ int main(int argc, char **argv) file = NULL; } } - - file = params.datafile; - - for (;;) { - char *sep = strchr(file, ':'); - if (sep) { - *sep = '\0'; - copy_file (ifd, file, 1); - *sep++ = ':'; - file = sep; - } else { - copy_file (ifd, file, 0); - break; - } - } + copy_datafile(ifd, params.datafile) } else if (params.type == IH_TYPE_PBLIMAGE) { /* PBL has special Image format, implements its' own */ pbl_load_uboot(ifd, ¶ms); -- 2.17.1