Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vs1T7-0016qa-1z for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Feb 2026 16:29:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vs1T6-003xAi-0J for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Feb 2026 16:29:04 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vs1T5-003xAQ-2C for pgsql-hackers@lists.postgresql.org; Mon, 16 Feb 2026 16:29:03 +0000 Received: from mail-ua1-x944.google.com ([2607:f8b0:4864:20::944]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vs1T2-00000000v0u-2wnY for pgsql-hackers@postgresql.org; Mon, 16 Feb 2026 16:29:02 +0000 Received: by mail-ua1-x944.google.com with SMTP id a1e0cc1a2514c-948af5e704cso894628241.3 for ; Mon, 16 Feb 2026 08:29:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dunslane-net.20230601.gappssmtp.com; s=20230601; t=1771259340; x=1771864140; darn=postgresql.org; h=in-reply-to:autocrypt:content-language:from:references:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=qkyKTvyFW4VRrNjGl6133zbOyo8quhPsqH7vEVbZAs0=; b=y/tRWe+4u7nxeqCLweY0RXilrYsIWmaXBmeBZPNhTs4swMiB2WQg9IMeD1kPg+sASH Kx3LFo7d+RH45ZODTxUoK7P9WAZdeAHKyXt8IqB4FoxrckXWlS7KdYa8TNHGPA4oG1iQ +1jXtZ9+K2js4YOhqwL7cndLGno6uOF9sRpHEA8skGpbxyDR7eoKgMWNb+vKiFO6YODM VZG0/erAlKw/uA6VMASRCBvbbZfBIj9uou3G4IQkqDxVERFfp2DPF7i1E8qBQNFe/E2j bpZWbIY5RSmEB65qUqlhe7C/pA70wJqgi1HLm9VBNrJ9aBv8BWDGHqteA5rc0PF4gt+f /B2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771259340; x=1771864140; h=in-reply-to:autocrypt:content-language:from:references:to:subject :user-agent:mime-version:date:message-id:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=qkyKTvyFW4VRrNjGl6133zbOyo8quhPsqH7vEVbZAs0=; b=SRuVMavNMQHv9yaHTNVuvCHaWgDLqWH327XsWn9b6eiA/mIXt7jMCR22VAy5CL1RIS Ygi8hZ8Uy51Ppj1J5X0AHt2aHUwjTrDIQNiFjztPZiyRh6IHOpTf1IVX2brVpKi4y9OL 6OFhSUTP9MNpCRgc2/d7NI79WHGIraB9mBcWE1VmcYh7+/238ZkVsV6Ge+g+jDnTPaGo 2pbbM58jHavByNeLG6R7jzc9u5v1WRdPg6XvI+sXmwB00XWXoEz/SE61msdcj9GR5I/u MEd/R5ezCy9D1GWJE4s6Gcn0DrFRAU7v9lAiJhlvXkHzeo/yMaXlx0KxRjo2vp5rsHAK yCng== X-Forwarded-Encrypted: i=1; AJvYcCVo3biF+BZVDoXgtUOiPS/6AsnG6kjExRysVOe6G4D7HfgNhRYHHxsNRTqAwAWyRF/7PFo/4O8ykvAaioYe@postgresql.org X-Gm-Message-State: AOJu0YzwgvY3TwRg/MkHP23O03fnoWWpdiYG5KAA8XdFXHwXbO+3QTw/ zEs/vaCNMMj4bd1Gq/63amJ9iJEjD2MVMPg/zpFnsU2QNOG9Fhr3+cF1L2mW6FxECEy9uP7fsHF AcwQNj77DJw== X-Gm-Gg: AZuq6aL8bXmJQe+qGFdQ+6yG5TIQfcKujeYq0u2t+7sHzahpjMYMhA+1GEf7hmKT9Ax 0flWKiWiea6OOZV7UHQz2Bg2yWSb6CBQH2H7sm9iQuWPh/zKks7Al9vVKljIh9Xl8F91FEllD70 cpjkft+rTUIbtgGVjsF2s2xyH9iv34eVbmI4nlxlmdnCAJlozOeb4CVG4PW0/nPHQRn1IOhBZrw s9IE3JZEPEOo4fLTRw9arlda9oJKUnKTFzsNGZMeGew8yBjiz67vzKf0ynRe61HOHBUpHM+6cez /JI7YDCSe2QqE/6cY20W3lsRIH0ctB+cgZ5PneIpBbQfG7xq16VGkaIcIeCXp6tZdFGMAMiA/59 /t9jko1rvRo4s9UUaE1ZhbPruyM5j+z4KBmAEBCSw5APusI/ZItxtFSgUa3E/8Ca8PBZ0cxoYE2 HszH15uQqLJ2xo+v7dtEYMuhNulCsDhw== X-Received: by 2002:a05:6102:c02:b0:5e5:5ed7:60b6 with SMTP id ada2fe7eead31-5fe1b013c1amr3060815137.39.1771259339740; Mon, 16 Feb 2026 08:28:59 -0800 (PST) Received: from ?IPV6:2605:a601:a6b0:500::1cb? ([2605:a601:a6b0:500::1cb]) by smtp.googlemail.com with ESMTPSA id a1e0cc1a2514c-94afd1ab72bsm7989479241.5.2026.02.16.08.28.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 16 Feb 2026 08:28:59 -0800 (PST) Content-Type: multipart/alternative; boundary="------------lVohkdpjzsipWmbrXy1okgDw" Message-ID: <3bd49b59-7a87-4ab6-9eac-59b5d9cb78de@dunslane.net> Date: Mon, 16 Feb 2026 11:28:58 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] pgindent truncates last line of files missing a trailing newline To: Akshay Joshi , pgsql-hackers References: From: Andrew Dunstan Content-Language: en-US Autocrypt: addr=andrew@dunslane.net; keydata= xsBNBE7KWFkBCAClridxur2AIc7eW2AR7izbfp3EnNefie2HbLF0izW5Ik5UjX2HBXBx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PLGOjdZ +kPiUcw5H85zf/yZJwQXzisXaNduwWB6Vads9YC9dj6kPR1c4VGRqAaYL++LAEOqrlvm2Tvq QqZRtnEAEQEAAcLAfAQYAQgAJgIbDBYhBOQ+WEYd/Hy/RGkVpZn6f8tZ/DuBBQJoGNI2BQkd EODdAAoJEJn6f8tZ/DuBfw0IAKTsfD40teP/pp+bsLLMSxPXUYrrprTj7WFB5v61p6dkpSr/ qXmMlyahdxQFaPmfVgVirB1Vk/kHiWNnnGjfUV9nB2Zg9LI0Xb9/ts3LsUiRWXzG3tkMY6XL vsVOxW4XFRND9l2q+WW93aZ1DZl+fqWfYgMvsusFRhmGFOKTRfKPta2Pkv+AhA24N4+PrR5p bU4k2MO8PAGiK8eaYKGFG1bHKuAvoDoF7WXJ3FHxuWqLnKEt4dfOLm5pAe3zq1Lt6q8azT9i QWGpSAK5vQUWQHBHpiDjdPeqKZ6HiAXIIKfSmb+jrvXBqoP+D6/K7rUjG2aXiRtTIAXms9sm VRu7cmw= In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------lVohkdpjzsipWmbrXy1okgDw Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2026-02-16 Mo 9:09 AM, Akshay Joshi wrote: > Hi Hackers, > > I have encountered a bug in "*src/tools/pg_bsd_indent/lexi.c"* where > pgindent was incorrectly dropping the final line of a file if that > line did not end with a newline character (\n). This occurred because > the EOF logic triggered a termination of the processing loop before > the remaining buffer was flushed to the output. > > *Steps to Reproduce:* > > 1. Create a *header/c* file with some content but no newline at the > very end. > 2. Run pgindent on those files. > 3. Check the file content. The file is now empty or missing the last > line. > > This patch ensures that had_eof states do not bypass the final buffer > processing, preserving the integrity of the source code regardless of > trailing whitespace. Yeah. I wonder if we shouldn't be just ensuring that there is a line feed at the end of the buffer, i.e. add one if it's not there. We shouldn't be adding files without a trailing LF, and ensuring there is one seems like a reasonable thing to do in pg_bsd_indent. cheers andrew -- Andrew Dunstan EDB:https://www.enterprisedb.com --------------lVohkdpjzsipWmbrXy1okgDw Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit


On 2026-02-16 Mo 9:09 AM, Akshay Joshi wrote:
Hi Hackers,

I have encountered a bug in "src/tools/pg_bsd_indent/lexi.c" where pgindent was incorrectly dropping the final line of a file if that line did not end with a newline character (\n). This occurred because the EOF logic triggered a termination of the processing loop before the remaining buffer was flushed to the output.

Steps to Reproduce:
  1. Create a header/c file with some content but no newline at the very end.
  2. Run pgindent on those files.
  3. Check the file content. The file is now empty or missing the last line.
This patch ensures that had_eof states do not bypass the final buffer processing, preserving the integrity of the source code regardless of trailing whitespace.


Yeah. I wonder if we shouldn't be just ensuring that there is a line feed at the end of the buffer, i.e. add one if it's not there. We shouldn't be adding files without a trailing LF, and ensuring there is one seems like a reasonable thing to do in pg_bsd_indent.


cheers


andrew


--
Andrew Dunstan
EDB: https://www.enterprisedb.com
--------------lVohkdpjzsipWmbrXy1okgDw--