From patchwork Thu Aug 3 11:43:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 130502 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp1087014vqx; Thu, 3 Aug 2023 04:43:27 -0700 (PDT) X-Google-Smtp-Source: APBJJlGiObX5lNyx5PDE8M1kGSArCzWMfnmJUrNFZy+ecJX/BoA3h97q1SwZ4ZWCRYTe/TeeNB3O X-Received: by 2002:a05:6512:3e02:b0:4f9:596d:c803 with SMTP id i2-20020a0565123e0200b004f9596dc803mr9709405lfv.53.1691063007081; Thu, 03 Aug 2023 04:43:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691063007; cv=none; d=google.com; s=arc-20160816; b=ytnzAh26JgTXzNK9xNi1aLz4YQCpCjrSmsKoxoHVqth91y1AnqW+mabdJIPZ2Sf7UC RhO5HR0NPaUap6Uo4S0JOJmVEEqqwn2tWYs5kkyxN0vrwL5ZpIAucabBAWpTMf/3DmEh GqpTOrDn1JPVkH/ODcgiRpd59h6jPHso9qp29FRAW5gLNFmSP3YDLy9BXSzraiKtrLti 86UKAiBx/1/8QevbCZwUyRYEJv8xcfEnhhxSqHTGNIOKr3tZ3gTk8laS3ihMGcjn9spy Bdued8TQjo/wd3Y7l+JB1pRN394wEweGY6U1rl6odnJuucl4vnDXYE0OJVGaGEhUlCcx IGPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=ikK6mD5f6Ebiq3LLZsw0iALeZNPIfzPnhvmvp1NRS8Y=; fh=HNIqzTA9Dp00ovCAyCdXfuEvWDT00OlFxFRPLybXRis=; b=zCbaVBQxmGbpA7yAirbQTlD4PSJVPRpAD+a+4+/ajOxWpOe7rymBichOYBrdOEwJmn jSHmT75K1BT4A/ccLobXb1AxGgTHe0WciIbyWxNe47BEK4aTcDikW1xyNJLhWJBBxqsM tdpYuTUd0ApoBlDcMOSo8nCeaODTI/WFbdW3z4zwUTIKTsZHY3mEAei2qtQOOKNHVMSr rEKXZ7RP36YcmrL2ta88VEypTjd/Pq5mURO6tSMIyxy1N7uNdBim4FoRrSUke+VrPnW6 ZxpR5Ryw/14810P86EuzXMFzdGqevgCOVt7gyVWSlUz3DcX5zHm3ONDe54A3ojnIPL5y rV2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=ioz58UsF; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id k21-20020aa7d8d5000000b00522def3c64csi4589810eds.615.2023.08.03.04.43.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 04:43:27 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=ioz58UsF; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 85449385843A for ; Thu, 3 Aug 2023 11:43:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 85449385843A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1691062994; bh=ikK6mD5f6Ebiq3LLZsw0iALeZNPIfzPnhvmvp1NRS8Y=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ioz58UsFx0sfxGePzW4qybn69fPEUttZvSjE5yBY0jdKI1xuZXpfWoDXvq1IzAfBh MPi9RC5EuHio7IGdAdIbb7vS9j2qU7CJ+l/DPD/+X4ADZJlsgACyQa5D7ehTvnzrKL 9v5JELxfSwtIDNaIAZ1Fi69JkNC+H9Yx8tQM/ccE= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-ot1-x333.google.com (mail-ot1-x333.google.com [IPv6:2607:f8b0:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id 338D23858035 for ; Thu, 3 Aug 2023 11:43:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 338D23858035 Received: by mail-ot1-x333.google.com with SMTP id 46e09a7af769-6bcaa6d5e2cso780368a34.3 for ; Thu, 03 Aug 2023 04:43:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691062985; x=1691667785; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ikK6mD5f6Ebiq3LLZsw0iALeZNPIfzPnhvmvp1NRS8Y=; b=Y/Dorw5bA6sj8Yqd6S8IpMEKceTjvYX1yw4c0VjgsLcFKzQG0yn/WtWwdkp2lMJz+d unaOTOWzjbWQNSYCZt1YB0TEHTnMJfymXAZin5nb8SaPaHm5Fskb2OXEdi13GHLHN3O2 kV9dEZTxmzx64nc4cT9Vij01is7ks+k13kk8NpLCyuAPo65fqaSo2chHYiDh7bfQ7rZg +WqDFxSIlGXQFFpvpyRK1EqUZikqQVppr/sCn/y8VJcBD48G1km9sK5Yw6c7x9q4H5Y6 uZghot/elV8cOeJ8fI3tqWTkRpxjVnsCsTZMzGSG7pPPqZJUGQu8imR9XxvT3ud8rqPr QEHQ== X-Gm-Message-State: ABy/qLYah8U2CcnV4oK4FY8aiYVaaZ6jDlG7fSuN2qqJUZD+kUWbQA5k lw6fqRgKfnX5a2S766mTFmoCd8heoGs= X-Received: by 2002:a05:6808:124e:b0:3a1:d075:348b with SMTP id o14-20020a056808124e00b003a1d075348bmr19398746oiv.59.1691062984882; Thu, 03 Aug 2023 04:43:04 -0700 (PDT) Received: from squeak.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id c19-20020aa781d3000000b0068779015507sm2702287pfn.194.2023.08.03.04.43.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 04:43:04 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 9DA7911427AD; Thu, 3 Aug 2023 21:13:01 +0930 (ACST) Date: Thu, 3 Aug 2023 21:13:01 +0930 To: binutils@sourceware.org Subject: cris: sprintf sanitizer null destination pointer Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3034.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alan Modra via Binutils From: Alan Modra Reply-To: Alan Modra Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773208083459537218 X-GMAIL-MSGID: 1773208083459537218 Simplify the sprintf calls, and use sprintf return value. Older code in binutils avoided using the sprintf return count of chars printed, because with some older C libraries it wasn't reliable. Nowadays it should be OK to use (and we already use the return value elsewhere). sprintf can't return an error status of -1 here. * cris-dis.c (format_dec): Avoid sanitizer warning. Use sprintf return value rather than calling strlen. diff --git a/opcodes/cris-dis.c b/opcodes/cris-dis.c index b8eaa4b7942..681fccf0dca 100644 --- a/opcodes/cris-dis.c +++ b/opcodes/cris-dis.c @@ -580,12 +580,7 @@ static char * format_dec (long number, char *outbuffer, int signedp) { last_immediate = number; - if (signedp) - sprintf (outbuffer, "%ld", number); - else - sprintf (outbuffer, "%lu", (unsigned long) number); - - return outbuffer + strlen (outbuffer); + return outbuffer + sprintf (outbuffer, signedp ? "%ld" : "%lu", number); } /* Format the name of the general register regno into outbuffer. */