From patchwork Thu Oct 10 02:41:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Collin Funk X-Patchwork-Id: 98631 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5A0E9385E45B for ; Thu, 10 Oct 2024 02:45:01 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by sourceware.org (Postfix) with ESMTPS id 72421385DDC4 for ; Thu, 10 Oct 2024 02:44:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 72421385DDC4 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 72421385DDC4 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::629 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728528276; cv=none; b=OmRVtKVs350NK0qqS9qZAUoRhVz4K7nbrYJkq+pGvAZtAzXszHP4Uvvl4UTI1t+3VtyRrMmsix0UFJWuVcyKCHHf+bMIIGLX3BKzJ+eTt3jnIRPesNf3GEhXafaJ2VeCAgLkixgNiPLLenzohpY5evVJBRGEEpWnVcbTAY700wg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728528276; c=relaxed/simple; bh=H5eOoN1ICKQEiKJPRNHANJIGUctmEhAiXp7tepAzFyU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=nMR4E4CCu4N5lBuvKqpsc7/Y4+kNZEOeqdD3/X06oYOQORD5ETtfPJyxvwokYBPLGwd0S3MT04Hj8o6lW3jibhG589lSZkzAv5OS5nf7WU5f53cR1NvnDVITl1EhiKEEwxg0EYxszj43IgSbeP/tRraMCI9ZCStyLDaMs3uZ44I= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-20c5a7b2908so3292285ad.1 for ; Wed, 09 Oct 2024 19:44:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728528271; x=1729133071; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=dWn1YszcX7wbdY0c0sUacmJMOJiYkL/mDinkdQkIVUk=; b=dq00daHWYIsmkXhx/NMr3QRMQb7R7vFtDYXITIr5cx40cvU2DpZNFfKe6VL7yDlVjk ge/LfejmBn8c1p9wqQWfiIDlz8+qer4hcZE2uSWl2uNxKEqfV/hukQuEiZbrdT6kcwNS a4WIRJAPK/ORTgA/YNTLd9OAxD6E7EzbC0MQvfJWPduv4+hAUWXDf9XBnJWlinysBA5c mGgookMkdWaMM2cYyNCO21UUUOdCuw6KEJ6wDx6hFyuVs2nFlHmNwPVt4nnnz5q4QNVM 4DaOJWlpV8YX2A+LhSt+yCZkzj1NpBGIIW6/NHvO4M4PqdxXpoV8gXFqeawZSdX1Kk+H DZQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728528271; x=1729133071; 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=dWn1YszcX7wbdY0c0sUacmJMOJiYkL/mDinkdQkIVUk=; b=BuaxxmhjOJzlicPnQ+mKXQxoWjuHS6aW4dc4a8ksbRY6jku1pFzKK+GuFHsX67xoAG rGbApg4+3eDvz0U4smL6zroN7GYi9n2ul0ZrCdqOYPmsYJ4GxHidnsf22F8pfZ9SGUgR lSIv7lWqDU+MptAotqbgyE/VvmRdpiYWN/ImPX3QyEdkTnwlEtQaRnkLI71qG3oX9vO1 eCBuh9lkEIIKC2XLpxuhflmFC02dBDd3lYIui9vID1bDE3MkYhKF/rI5YfwjAixvukee 138Xl08ByG9Qgcd1H7X01jPBPqfYwo/AhAlo8LoGkahbEFuhno9DAxusSZMPdrvpnizu 94Tw== X-Gm-Message-State: AOJu0YxUwUZc8MB8rWMPjDucFlVWnfOlLHiQGYTLkpd4aOeMYsSORt2O jjdGfNrOtuXTNdpNHx7GxDMT1HCD8nZYegbq9b1gky+ptBEmAYdCNu/vaQ== X-Google-Smtp-Source: AGHT+IEgnUZGOavW/ye8ORu0+aLqR4k9FdJR5hcVU3hDYxF1WVf8qDK0f8j3eVxV+YStcybbAMEfVQ== X-Received: by 2002:a17:902:dac7:b0:206:fd9d:b88d with SMTP id d9443c01a7336-20c637986d4mr76757525ad.61.1728528271352; Wed, 09 Oct 2024 19:44:31 -0700 (PDT) Received: from fedora.. (static-198-54-134-108.cust.tzulo.com. [198.54.134.108]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20c8c345e46sm1020365ad.271.2024.10.09.19.44.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2024 19:44:30 -0700 (PDT) From: Collin Funk To: libc-alpha@sourceware.org, carlos@redhat.com Cc: sam@gentoo.org, Collin Funk Subject: [PATCH v3] error: Don't call va_end twice [BZ #32233]. Date: Wed, 9 Oct 2024 19:41:47 -0700 Message-ID: <20241010024419.15389-1-collin.funk1@gmail.com> X-Mailer: git-send-email 2.46.2 MIME-Version: 1.0 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org Hi Carlos, Here is the same patch with an updated SHARED-FILES. I had a look at misc/error.h while I was at it, but all of the differences there are for Gnulib-specific wizardry. Not worth trying to keep them in sync. Collin -- 8< -- Sync to Gnulib commit ba9136b7646ef9e01ffad3ddcf232002354531d0 * misc/error.c (error_tail): Remove va_end call. (__error_internal): Use the '%u' conversion specifier instead of '%d' for 'line_number' which is an unsigned int. The following changes are only applicable to Gnulib: * misc/error.c: Use #include instead of #include "error.h" to silence Clang's -Winclude-next-absolute-path. (__error_internal, __error_at_line_internal, error_tail): Define to Gnulib symbols. [_WIN32 && !__CYGWIN__]: Include io.h for Windows function declarations. (strerror_r): Use a C23 compatible declaration. (program_name): Define to getprogname. (verror, verror_at_line) [GNULIB_defined_verror]: Define symbols. Signed-off-by: Collin Funk --- SHARED-FILES | 3 +- misc/error.c | 89 ++++++++++++++++++++++++++++++---------------------- 2 files changed, 54 insertions(+), 38 deletions(-) diff --git a/SHARED-FILES b/SHARED-FILES index d84e8e9697..310f21e65d 100644 --- a/SHARED-FILES +++ b/SHARED-FILES @@ -38,8 +38,9 @@ gnulib: malloc/obstack.c # Merged from gnulib 2014-6-23 malloc/obstack.h - # Merged from gnulib 2014-07-10 + # Merged from gnulib 2024-10-02 (gnulib commit ba9136b7646) misc/error.c + # Merged from gnulib 2014-07-10 misc/error.h misc/getpass.c misc/mkdtemp.c diff --git a/misc/error.c b/misc/error.c index e5d5588434..6816805326 100644 --- a/misc/error.c +++ b/misc/error.c @@ -20,9 +20,16 @@ #if !_LIBC # include +# define _GL_NO_INLINE_ERROR +# define __error_internal(status, err, fmt, args, flags) \ + verror (status, err, fmt, args) +# define __error_at_line_internal(status, err, file, line, fmt, args, flags) \ + verror_at_line (status, err, file, line, fmt, args) +# define error_tail(status, err, fmt, args, flags) \ + error_tail (status, err, fmt, args) #endif -#include "error.h" +#include #include #include @@ -41,7 +48,7 @@ # include # define mbsrtowcs __mbsrtowcs # define USE_UNLOCKED_IO 0 -# define _GL_ATTRIBUTE_FORMAT_PRINTF(a, b) +# define _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD(a, b) # define _GL_ARG_NONNULL(a) #endif @@ -74,9 +81,9 @@ unsigned int error_message_count; extern void __error (int status, int errnum, const char *message, ...) __attribute__ ((__format__ (__printf__, 3, 4))); extern void __error_at_line (int status, int errnum, const char *file_name, - unsigned int line_number, const char *message, - ...) - __attribute__ ((__format__ (__printf__, 5, 6)));; + unsigned int line_number, const char *message, + ...) + __attribute__ ((__format__ (__printf__, 5, 6))); # define error __error # define error_at_line __error_at_line @@ -92,43 +99,52 @@ extern void __error_at_line (int status, int errnum, const char *file_name, # include # include -# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ +# if defined _WIN32 && ! defined __CYGWIN__ /* Get declarations of the native Windows API functions. */ # define WIN32_LEAN_AND_MEAN # include /* Get _get_osfhandle. */ -# include "msvc-nothrow.h" +# if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +# else +# include +# endif # endif /* The gnulib override of fcntl is not needed in this file. */ # undef fcntl -# if !HAVE_DECL_STRERROR_R +# if !(GNULIB_STRERROR_R_POSIX || HAVE_DECL_STRERROR_R) # ifndef HAVE_DECL_STRERROR_R "this configure-time declaration test was not run" # endif # if STRERROR_R_CHAR_P -char *strerror_r (); +char *strerror_r (int errnum, char *buf, size_t buflen); # else -int strerror_r (); +int strerror_r (int errnum, char *buf, size_t buflen); # endif # endif -/* The calling program should define program_name and set it to the - name of the executing program. */ -extern char *program_name; +# define program_name getprogname () -# if HAVE_STRERROR_R || defined strerror_r +# if GNULIB_STRERROR_R_POSIX || HAVE_STRERROR_R || defined strerror_r # define __strerror_r strerror_r -# endif /* HAVE_STRERROR_R || defined strerror_r */ -#endif /* not _LIBC */ +# endif /* GNULIB_STRERROR_R_POSIX || HAVE_STRERROR_R || defined strerror_r */ + +# if GNULIB_defined_verror +# undef verror +# endif +# if GNULIB_defined_verror_at_line +# undef verror_at_line +# endif +#endif /* not _LIBC */ #if !_LIBC /* Return non-zero if FD is open. */ static int is_open (int fd) { -# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ +# if defined _WIN32 && ! defined __CYGWIN__ /* On native Windows: The initial state of unassigned standard file descriptors is that they are open but point to an INVALID_HANDLE_VALUE. There is no fcntl, and the gnulib replacement fcntl does not support @@ -173,9 +189,9 @@ print_errno_message (int errnum) { char const *s; -#if defined HAVE_STRERROR_R || _LIBC +#if _LIBC || GNULIB_STRERROR_R_POSIX || defined HAVE_STRERROR_R char errbuf[1024]; -# if _LIBC || STRERROR_R_CHAR_P +# if _LIBC || (!GNULIB_STRERROR_R_POSIX && STRERROR_R_CHAR_P) s = __strerror_r (errnum, errbuf, sizeof errbuf); # else if (__strerror_r (errnum, errbuf, sizeof errbuf) == 0) @@ -199,9 +215,9 @@ print_errno_message (int errnum) #endif } -static void _GL_ATTRIBUTE_FORMAT_PRINTF (3, 0) _GL_ARG_NONNULL ((3)) +static void _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (3, 0) _GL_ARG_NONNULL ((3)) error_tail (int status, int errnum, const char *message, va_list args, - unsigned int mode_flags) + unsigned int mode_flags) { #if _LIBC int ret = __vfxprintf (stderr, message, args, mode_flags); @@ -212,7 +228,6 @@ error_tail (int status, int errnum, const char *message, va_list args, #else vfprintf (stderr, message, args); #endif - va_end (args); ++error_message_count; if (errnum) @@ -234,7 +249,7 @@ error_tail (int status, int errnum, const char *message, va_list args, Exit with status STATUS if it is nonzero. */ void __error_internal (int status, int errnum, const char *message, - va_list args, unsigned int mode_flags) + va_list args, unsigned int mode_flags) { #if defined _LIBC /* We do not want this call to be cut short by a thread @@ -281,8 +296,8 @@ int error_one_per_line; void __error_at_line_internal (int status, int errnum, const char *file_name, - unsigned int line_number, const char *message, - va_list args, unsigned int mode_flags) + unsigned int line_number, const char *message, + va_list args, unsigned int mode_flags) { if (error_one_per_line) { @@ -290,13 +305,13 @@ __error_at_line_internal (int status, int errnum, const char *file_name, static unsigned int old_line_number; if (old_line_number == line_number - && (file_name == old_file_name - || (old_file_name != NULL - && file_name != NULL - && strcmp (old_file_name, file_name) == 0))) + && (file_name == old_file_name + || (old_file_name != NULL + && file_name != NULL + && strcmp (old_file_name, file_name) == 0))) - /* Simply return and print nothing. */ - return; + /* Simply return and print nothing. */ + return; old_file_name = file_name; old_line_number = line_number; @@ -325,11 +340,11 @@ __error_at_line_internal (int status, int errnum, const char *file_name, } #if _LIBC - __fxprintf (NULL, file_name != NULL ? "%s:%d: " : " ", - file_name, line_number); + __fxprintf (NULL, file_name != NULL ? "%s:%u: " : " ", + file_name, line_number); #else - fprintf (stderr, file_name != NULL ? "%s:%d: " : " ", - file_name, line_number); + fprintf (stderr, file_name != NULL ? "%s:%u: " : " ", + file_name, line_number); #endif error_tail (status, errnum, message, args, mode_flags); @@ -342,12 +357,12 @@ __error_at_line_internal (int status, int errnum, const char *file_name, void error_at_line (int status, int errnum, const char *file_name, - unsigned int line_number, const char *message, ...) + unsigned int line_number, const char *message, ...) { va_list ap; va_start (ap, message); __error_at_line_internal (status, errnum, file_name, line_number, - message, ap, 0); + message, ap, 0); va_end (ap); }