🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.linux.misc
Article #2161

Re: Substantive Comments Please: GCC vs. LLMV

#2161
From: Chris Ahlstrom
Date: Wed, 04 Nov 2026 11:39
70 lines
4733 bytes
Richard Kettlewell wrote this screed in ALL-CAPS (fixed):

> Chris Ahlstrom <OFeem1987@teleworm.us> writes:
>> rbowman wrote this screed in ALL-CAPS (fixed):
>>> On Mon, 2 Nov 2026 14:18:27 -0500, Chris Ahlstrom wrote:
>>>> It found a few issues in a couple of my projects, a few issues
>>>> important.
>>>> There is one that I don't get
>>>> 
>>>>    subprojects/libcfg66/src/util/filefunctions.cpp:1138:33: warning:
>>>>    Memory allocated by 'new[]' should be deallocated by 'delete[]',
>>>>    not 'getline()' [unix.MismatchedDeallocator]
>>>> 
>>>>  1138 |   ssize_t count { getline(&destination, &maxim, input) };
>>>>       |                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>> 
>>>> I guess I need to use malloc() instead.
>>>
>>> Did you allocate destination with new? getline will malloc a buffer
>>> if you pass in NULL.
>>
>> Yes, and I know that from the man page.
>>
>> The point is scan-build complaining about something getline() will
>> not do in the given use case.
>>
>> A limitation of static analysis, perhaps.
>
> There’s not enough context to give a completely definitive answer, but:
>
> 1) Heap memory can be managed with new/delete, or with
>    malloc/realloc/free, but not both. The consequences of playing
>    mix-and-match vary between platform, so you might get away with it in
>    some cases, by luck, but static analysis tools will consider it a
>    bug, if they’re smart enough to notice.

The tool is clang's scan-build. Fortunately, meson automatically
sets a build to use it if it is installed. Otherwise I'd be too
damned lazy to use it :-D

> 2) In getline(), if *lineptr!=NULL then it will call realloc() on it if
>    the line from stream needs more than *n bytes (using argument names
>    from [1]). So passing a pointer allocated with new to it is a bug,
>    for the reasons given in (1) above.
>
> 3) The diagnostic referring to deallocation reather than realloc is
>    probably a (trivial) bug in the tool - for example it may model
>    realloc as malloc+free, which isn’t unreasonable as such, but leads
>    to an opaque diagnostic.
>
> The only case where it would not be a bug is if the line read by
> getline() can never possibly exceed the initial allocation. Whether this
> is true in your use case I don’t know, but your static analysis tool
> either couldn’t prove that it was or more likely, isn’t equipped to do
> so.
>
> [1] https://man7.org/linux/man-pages/man3/getline.3.html

I bit the bullet and went to malloc()/free().

Now I got a couple of "Method called on moved-from object"
warnings to fix. (A needless test of movement in a test app.)

-- 
I will not play at tug o' war.  I'd rather play at hug o' war,
Where everyone hugs Instead of tugs,
Where everyone giggles And rolls on the rug,
Where everyone kisses, And everyone grins,
And everyone cuddles, And everyone wins.
		-- Shel Silverstein, "Hug o' War"
Technical Details
Message-ID: <11cf5l0$kqbj$1@dont-email.me>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <18e37e973e22a7a6$1$3179723$802601b3@news.usenetexpress.com> <11c7kmg$22g7e$1@dont-email.me> <11c80ic$26et9$4@dont-email.me> <11cafc8$31pdt$1@dont-email.me> <11canpv$35aju$1@dont-email.me> <nks9f4F2rmsU5@mid.individual.net> <11ccn72$3p6mj$2@dont-email.me> <wwvtslxsqkd.fsf@LkoBDZeT.terraraq.uk>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Chris Ahlstrom <OFeem1987@teleworm.us>
Newsgroups: comp.os.linux.misc
Subject: Re: Substantive Comments Please: GCC vs. LLMV
Date: Wed, 4 Nov 2026 06:39:16 -0500
Organization: None
Lines: 70
Message-ID: <11cf5l0$kqbj$1@dont-email.me>
References: <18e37e973e22a7a6$1$3179723$802601b3@news.usenetexpress.com>
 <11c7kmg$22g7e$1@dont-email.me> <11c80ic$26et9$4@dont-email.me>
 <11cafc8$31pdt$1@dont-email.me> <11canpv$35aju$1@dont-email.me>
 <nks9f4F2rmsU5@mid.individual.net> <11ccn72$3p6mj$2@dont-email.me>
 <wwvtslxsqkd.fsf@LkoBDZeT.terraraq.uk>
Reply-To: OFeem1987@teleworm.us
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 04 Nov 2026 11:41:21 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="682355"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/gjEreKeED9NIUR6jPXNpN"; posting-host="ac4f3576e06fda87c4d91572134bf0c4"
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:Kp0aBR0k1qrZYkBRpjl8IjQRa7A= sha256:sqB+Gp3FLNZwaoMolwvGrojLLtfpcOX8HVT6lCrCG9k=
	sha1:zICwqIrO0bh10MkoA66bqRRXYKY= sha256:NT/A+ZPrRcwab7NWn/3LjJNJeRQJpVJaaI1CbZeb6hk=
X-User-Agent: Microsoft Outl00k, Usenet K00k Editions
X-Mutt: The most widely-used MUA
X-Slrn: Why use anything else?
X-Face: 63n<76,LYJQ2m#'5YL#.T95xqyPiG`ffIP70tN+j"(&@6(4l\7uL)2+/-r0)/9SjZ`qw=
 Njn mr93Xrerx}aQG-Ap5IHn"xe;`5:pp"$RH>Kx_ngWw%c\+6qSg!q"41n2[.N/;Pu6q8?+Poz~e
 A9? $6_R7cm.l!s8]yfv7x+-FYQ|/k