Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp988742iob; Fri, 13 May 2022 18:45:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxIh9nsWCkxoxCDz2ossy9qPuqMSlz+/2DF3/diN1TLPtxo+AWe3dyWBYSN2P9A5yzV7XaG X-Received: by 2002:a05:600c:3549:b0:394:89ba:e1be with SMTP id i9-20020a05600c354900b0039489bae1bemr6782157wmq.181.1652492723880; Fri, 13 May 2022 18:45:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652492723; cv=none; d=google.com; s=arc-20160816; b=SY2Y+IfEGnBqV3KWUb4bZwAv+t9UaMX8CCr4BVnksUerxg1igDHY+36x/FR9gK90ZP Fws+yLEU58EJo2sxlbSoNWSLQc9iKMzyvEjzUytVHPglHtvjGO1n+KbyYK0PpAVCjW1c QZsCbmqPYeyCXS946Qa0zOAxZL98pPC9yU3A7C7i5UPDwYI6PCuHgbPiWhM9gRAE4DU0 gJlj8nyMavsEbOuRuZ9YJlbY+w+DzAgFwau5qvtcA/Yb23OOLdEcadjjmRzoTkhS72TL yEBCRykY8LbqNkTfQKk8dqwqNA5ERnuuc81Og5JQXcLfOSB0v5GIj+L3pfuHGvLBZpmR 0p9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=7RGSIaTr15jsqF00u7CDlhQuIiepeTjsk9/kLEuXKxM=; b=EmkSnQ5i/e7VCZKurqO3NA4pDR33aXPxon1dUsq1N3RzIJ3jKeOSqazUX7NTebUexL Zye8dp/wfJXV27dd+z1juWlF/5POJnmUhwLKHpm4Mev0uDwmVu8fPl1bNDzwFvA87RIJ ejGxD07lW84QDhW5FzRPa7z4PdiV0KYwxzdR9N2Fo4SrcyKtdzv/mAQnea0dRibmbUEk gGui5ONLYyYYRow/29L/ljOPCHmnIpPbKp6mEb+lu6ogKiahhu9FGtFPO6Xds26gnGLI 611VtlkiFGA4vWZeITHLSEWqOmbR8/41JcwFOnijlAY3IH3JrQBgk39MpVJHayudsPr4 IzAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gnuweeb.org header.s=default header.b=HHlioj8Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnuweeb.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id y1-20020a056000168100b0020916c700f3si4819547wrd.682.2022.05.13.18.45.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 18:45:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gnuweeb.org header.s=default header.b=HHlioj8Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnuweeb.org Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9C4DB2F86BB; Fri, 13 May 2022 17:10:28 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352514AbiELQOv (ORCPT + 99 others); Thu, 12 May 2022 12:14:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233278AbiELQOu (ORCPT ); Thu, 12 May 2022 12:14:50 -0400 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC5ED6623B for ; Thu, 12 May 2022 09:14:49 -0700 (PDT) Received: from [192.168.88.87] (unknown [180.242.99.67]) by gnuweeb.org (Postfix) with ESMTPSA id 02E317F628; Thu, 12 May 2022 16:14:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1652372089; bh=3U63MfFe6NNlA7+9OBTVpsTNg4BhGFmC0heC1eTNPn0=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=HHlioj8YxvRo7x+f4nbXrHcO5+g3bxMx7SRXW142HTO3mHdehBK/a8rmh2dZeFKYn XhLlqi/qE2AvWMJEUpVX/S50PYuFgakb+Ob9XOnwWRRakPLYjEmQCB8q1IP3OGCuwj +vZ883/d311UUy85Yab3+b8Gxj1x8I+Q7KoIgR6INIwJonBawsKD4oC/mnpDE5mvAt MvBLJ4yXTesfbMl07SLVYdOO/3LXcLSJm1T9ldruIs/qN0o7Wol4jwofXm1wM79NJf RIBIwIDE78ze1OKHfdxj89R0jqb5MXWB1boS8Ab9Q0x2Wtb6h3j5JhEkiAX8PskeOs 4BWfm9SPsUmSQ== Message-ID: Date: Thu, 12 May 2022 23:14:35 +0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Subject: Re: [PATCH 1/1] tools/nolibc/stdio: Add format attribute to enable printf warnings Content-Language: en-US To: Alviro Iskandar Setiawan Cc: GNU/Weeb Mailing List , Linux Kernel Mailing List References: <20220509065445.3912334-1-alviro.iskandar@gnuweeb.org> <20220509065445.3912334-2-alviro.iskandar@gnuweeb.org> From: Ammar Faizi In-Reply-To: <20220509065445.3912334-2-alviro.iskandar@gnuweeb.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I will send it to Willy soon. Anyway, __attribute__ can have multiple arguments, so no need to write it twice. I simplified it, the end result patch below... Thank you! --- From 7998cda9acdbfec6d6ba73642c27d710996c27ed Mon Sep 17 00:00:00 2001 From: Alviro Iskandar Setiawan Subject: tools/nolibc/stdio: Add format attribute to enable printf warnings When we use printf and fprintf functions from the nolibc, we don't get any warning from the compiler if we have the wrong arguments. For example, the following calls will compile silently: ``` printf("%s %s\n", "aaa"); fprintf(stdout, "%s %s\n", "xxx", 1); ``` (Note the wrong arguments). Those calls are undefined behavior. The compiler can help us warn about the above mistakes by adding a `printf` format attribute to those functions declaration. This patch adds it, and now it yields these warnings for those mistakes: ``` warning: format `%s` expects a matching `char *` argument [-Wformat=] warning: format `%s` expects argument of type `char *`, but argument 4 has type `int` [-Wformat=] ``` [ammarfaizi2: Simplify the attribute placement.] Signed-off-by: Alviro Iskandar Setiawan Signed-off-by: Ammar Faizi --- tools/include/nolibc/stdio.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h index 15dedf8d0902..a3cebc4bc3ac 100644 --- a/tools/include/nolibc/stdio.h +++ b/tools/include/nolibc/stdio.h @@ -273,7 +273,7 @@ int vfprintf(FILE *stream, const char *fmt, va_list args) return written; } -static __attribute__((unused)) +static __attribute__((unused, format(printf, 2, 3))) int fprintf(FILE *stream, const char *fmt, ...) { va_list args; @@ -285,7 +285,7 @@ int fprintf(FILE *stream, const char *fmt, ...) return ret; } -static __attribute__((unused)) +static __attribute__((unused, format(printf, 1, 2))) int printf(const char *fmt, ...) { va_list args; -- Ammar Faizi