From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fencepost.gnu.org (fencepost.gnu.org [IPv6:2001:470:142:3::e]) by sourceware.org (Postfix) with ESMTPS id 275623858D1E; Tue, 24 Jan 2023 13:10:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 275623858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gnu.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gnu.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=Tjcf5r50I8/i9WGZ7rit95pvIzJ7Gx2EZgDyEE8UEDg=; b=jMwU9Bbtg0qL Wwco58YpSP+U0EjlEs9NHRQEUKGF8QpwOMlsAP+FAmG4NcRLhKWkolPRlZHsH3odKMdYBuUJcvzWI BD8dqydRlkhKmZfq/0fRl3yNdyHvHK9Ww+pFPbUT/ndU8BE+ic/i6pu/Z9EdN4iCO+QF2rqVvauRo U0XF7NWmsvRIy2tqR37Zq7RDOie0KCp+FeuWpO7+VU7cwITwAsNnNAjusu2924JypIFsuMy6x/jYU 599QxEdMZX1H1sDTzVAsMZS02cE6tW9/AQMuZ1NU7oYBisl2tD1MRAsfT7/Znpf0YUM04NWSECE+/ dIbo1FF1lVxA/H5G0iDc6g==; Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pKJ4j-0000fu-Cu; Tue, 24 Jan 2023 08:10:57 -0500 Date: Tue, 24 Jan 2023 15:11:07 +0200 Message-Id: <83tu0ggjro.fsf@gnu.org> From: Eli Zaretskii To: Ian Lance Taylor Cc: gcc@hazardy.de, gcc-patches@gcc.gnu.org, gcc@gcc.gnu.org In-Reply-To: (message from Ian Lance Taylor via Gcc on Mon, 23 Jan 2023 15:00:56 -0800) Subject: Re: [PATCH 2/4] libbacktrace: detect executable path on windows References: <20230120105409.54949-1-gcc@hazardy.de> <20230120105409.54949-2-gcc@hazardy.de> X-Spam-Status: No, score=2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_BARRACUDACENTRAL,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: ** X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: > Date: Mon, 23 Jan 2023 15:00:56 -0800 > Cc: gcc-patches@gcc.gnu.org, gcc@gcc.gnu.org > From: Ian Lance Taylor via Gcc > > > +#ifdef HAVE_WINDOWS_H > > + > > +static char * > > +windows_get_executable_path (char *buf, backtrace_error_callback error_callback, > > + void *data) > > +{ > > + if (GetModuleFileNameA (NULL, buf, MAX_PATH - 1) == 0) > > + { > > + error_callback (data, > > + "could not get the filename of the current executable", > > + (int) GetLastError ()); > > + return NULL; > > + } > > + return buf; > > +} > > Thanks, but this seems incomplete. The docs for GetModuleFileNameA > say that if the pathname is too long to fit into the buffer it returns > the size of the buffer and sets the error to > ERROR_INSUFFICIENT_BUFFER. It seems to me that in that case we should > allocate a larger buffer and try again. This is correct in general, but not in this particular case. > On Windows it seems that MAX_PATH is not > a true limit, as an extended length path may be up to 32767 bytes. The limit of 32767 characters (not bytes, AFAIK) is only applicable when using the Unicode (a.k.a. "wide") versions of the Windows Win32 APIs, see https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation Since the above code uses GetModuleFileNameA, which is an "ANSI" single-byte API, it is still subject to the MAX_PATH limitation, and MAX_PATH is defined as 260 on Windows headers.