From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1qKPYO-0001Xc-1C for mharc-grub-devel@gnu.org; Fri, 14 Jul 2023 16:38:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qKPYM-0001XP-2L for grub-devel@gnu.org; Fri, 14 Jul 2023 16:38:14 -0400 Received: from mail-qk1-x72c.google.com ([2607:f8b0:4864:20::72c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qKPYJ-0001sb-JG for grub-devel@gnu.org; Fri, 14 Jul 2023 16:38:13 -0400 Received: by mail-qk1-x72c.google.com with SMTP id af79cd13be357-7659dc74d91so237016285a.0 for ; Fri, 14 Jul 2023 13:38:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20221208.gappssmtp.com; s=20221208; t=1689367089; x=1691959089; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=WV2YUQPzB5BVye3d1cU+o3oLMdR/m37wt4akjf1Z8wY=; b=OqhSRbs5f9mRaYC6f0Ol2hsaOrfNHMrhTzM42iv8+QdSzJiUP++fI7P78voXAbTa4c kMBsBbck4xYKGhtzQ6mLte9tYxs+ZxxT7RLDc3J2vQ5B2gbjB0KsTJAL1BQZIIdrd5YE 6uPpnU7i1UX9r647OSIgUFhEH84XJvUNyBt18TbFWRby9InozJxJuFUnpfwPgYJEh1VC Dnu4qYyonuclLfn3Qpp25ANPGm0oOTmP1XEUJA5Lt5EgbU60smPQyFJRNdEJX8pV66Np qsJk8KQWr4ZXuxAWZtOwS8IPHUIhb4Jqxid90x/mZkZCwkwA2bWj2C/YV5jGXd2IYyAa X0SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689367089; x=1691959089; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=WV2YUQPzB5BVye3d1cU+o3oLMdR/m37wt4akjf1Z8wY=; b=WGLK+NtjrzSo2myItrUqbZDEErbFw3JnHOtGHVQ6GFXgSyBlVGdamHchXIJzkYwDBH 1DYV7iL3K7XXaiEftzleJ86WU//YI8yrqpd1qDDvueKYTAyPQCp6XkjovPiGjlGOZnpA HRKxtlsa5jCgwuciwabavFm4zJgN/6c/j3iItwLO+FMCthA628a2XiLuPmjw2uOtnnMY q7oM3AFB7r1WlZj/eNBamFdjhdV9I+z604bQ30oXgpKpsBK7Dq13acoN1VV/JUVXaIZT XiOza8vpCeUFknnPWY/rYDd3/zGmkKmYSgpoCbpoZrE6n5aB1K9y9vG7mTRPaJk6ITy4 hJIg== X-Gm-Message-State: ABy/qLZn/q4Bx5+DCOFoSJ5fVy5+Y6dc2Vx/Fz0+d9L/lFm3N49z6bUX wB3qNVLRU8A7UpNyDMli9Yi82XjCizegJSYwvaOf0g== X-Google-Smtp-Source: APBJJlFz0xhT/BfA0l6gmUIcYAcNbQHb5Dwy9sIQWTAtv6FliWxiD1xjLjKon2zeGww6+bvI3c/8Vw== X-Received: by 2002:a37:b484:0:b0:765:9c48:a930 with SMTP id d126-20020a37b484000000b007659c48a930mr5899606qkf.67.1689367089066; Fri, 14 Jul 2023 13:38:09 -0700 (PDT) Received: from localhost.localdomain ([199.58.83.12]) by smtp.gmail.com with ESMTPSA id u14-20020a05620a120e00b00767b24f68edsm4110767qkj.62.2023.07.14.13.38.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jul 2023 13:38:08 -0700 (PDT) From: Glenn Washburn To: grub-devel@gnu.org, Daniel Kiper Cc: Glenn Washburn Subject: [PATCH] misc: Add grub_sprintf() C99/POSIX non-conformance comment Date: Fri, 14 Jul 2023 15:38:00 -0500 Message-Id: <20230714203800.1779660-1-development@efficientek.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::72c; envelope-from=development@efficientek.com; helo=mail-qk1-x72c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 14 Jul 2023 20:38:14 -0000 Make clear that grub_sprintf() does not conform to C99/POSIX. It returns the number of bytes written, even when n is less than the length of the fully formatted string. Signed-off-by: Glenn Washburn --- grub-core/kern/misc.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c index 2890aad49fa7..634bf1441c63 100644 --- a/grub-core/kern/misc.c +++ b/grub-core/kern/misc.c @@ -983,6 +983,7 @@ write_number (char *str, grub_size_t *count, grub_size_t max_len, grub_size_t fo write_char (str, count, max_len, zerofill); } +/* See grub_snprintf for details of non-compliance to C99 and POSIX */ static int grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt0, struct printf_args *args) @@ -1204,6 +1205,14 @@ grub_vsnprintf (char *str, grub_size_t n, const char *fmt, va_list ap) return ret < n ? ret : n; } +/* + * Note: grub_snprintf does not conform to C99 nor the POSIX specs. + * Specifically, it returns the number of bytes written, minus the NULL + * byte. Whereas, the specs say that the return value should be the + * number of bytes that *would* be written if n were sufficiently large + * to contain the formatted output. This only matters when n is smaller + * than the formatted string. + */ int grub_snprintf (char *str, grub_size_t n, const char *fmt, ...) { -- 2.34.1