Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Fixing some undefined behavior

130 views
Skip to first unread message

woodb...@gmail.com

unread,
Jul 5, 2020, 3:58:04 PM7/5/20
to
Shalom

I have some undefined behavior in this program:

https://github.com/Ebenezer-group/onwards/blob/master/src/cmw/tiers/cmwA.cc

Basically I'm relying on some values being set
after using placement new:

req = &*pendingRequests.emplace_back(::new cmwRequest);
frntBuf.getPacket((::sockaddr*)&req->frnt, &req->frntLn);
gotAddr = true;
::new (req) cmwRequest(frntBuf);

I need to be able to use "frnt" and "frntLn" after that
last line. I guess the easiest way to handle it would be
to pass the "frnt" and "frntLn" fields to the constructor
I use with placement new. And then use them to initialize
the fields. Thanks in advance.


Brian
Ebenenezer Enterprises - Enjoying programming again.
https://webEbenezer.net

Öö Tiib

unread,
Jul 6, 2020, 8:20:03 AM7/6/20
to
On Sunday, 5 July 2020 22:58:04 UTC+3, woodb...@gmail.com wrote:
> Shalom
>
> I have some undefined behavior in this program:
>
> https://github.com/Ebenezer-group/onwards/blob/master/src/cmw/tiers/cmwA.cc
>
> Basically I'm relying on some values being set
> after using placement new:
>
> req = &*pendingRequests.emplace_back(::new cmwRequest);
> frntBuf.getPacket((::sockaddr*)&req->frnt, &req->frntLn);
> gotAddr = true;

Either ...

req->~cmwRequest();

... is missing from here or the next line is misplaced.

> ::new (req) cmwRequest(frntBuf);
>
> I need to be able to use "frnt" and "frntLn" after that
> last line. I guess the easiest way to handle it would be
> to pass the "frnt" and "frntLn" fields to the constructor
> I use with placement new. And then use them to initialize
> the fields. Thanks in advance.

Unsure what you do there and ask here. Better write short
fully compileable and runnable program that illustrates your
problem.

woodb...@gmail.com

unread,
Jul 6, 2020, 10:29:44 AM7/6/20
to
On Monday, July 6, 2020 at 7:20:03 AM UTC-5, Öö Tiib wrote:
> On Sunday, 5 July 2020 22:58:04 UTC+3, woodb...@gmail.com wrote:
> > Shalom
> >
> > I have some undefined behavior in this program:
> >
> > https://github.com/Ebenezer-group/onwards/blob/master/src/cmw/tiers/cmwA.cc
> >
> > Basically I'm relying on some values being set
> > after using placement new:
> >
> > req = &*pendingRequests.emplace_back(::new cmwRequest);
> > frntBuf.getPacket((::sockaddr*)&req->frnt, &req->frntLn);
> > gotAddr = true;
>
> Either ...
>
> req->~cmwRequest();
>
> ... is missing from here or the next line is misplaced.
>
> > ::new (req) cmwRequest(frntBuf);
> >

I guess it's missing.

> > I need to be able to use "frnt" and "frntLn" after that
> > last line. I guess the easiest way to handle it would be
> > to pass the "frnt" and "frntLn" fields to the constructor
> > I use with placement new. And then use them to initialize
> > the fields. Thanks in advance.
>
> Unsure what you do there and ask here. Better write short
> fully compileable and runnable program that illustrates your
> problem.

My explanation wasn't the greatest. It's related to this:
https://stackoverflow.com/questions/14659752/placement-new-and-uninitialized-pod-members


Brian

Öö Tiib

unread,
Jul 6, 2020, 11:15:52 AM7/6/20
to
If you need your cmwRequest object to be built in multiple steps
then implement such steps, perhaps even add a debug member that
indicates and allows to check its ripeness in debug builds. Do
not try to cheat pointlessly with confusing and illegal tricks.
Otherwise anyone can build your library with some ub-sanitiser,
get a crash, look at code and publish major "ewwww" about it.


woodb...@gmail.com

unread,
Jul 6, 2020, 2:40:47 PM7/6/20
to
On Monday, July 6, 2020 at 10:15:52 AM UTC-5, Öö Tiib wrote:
>
> If you need your cmwRequest object to be built in multiple steps
> then implement such steps, perhaps even add a debug member that
> indicates and allows to check its ripeness in debug builds. Do
> not try to cheat pointlessly with confusing and illegal tricks.
> Otherwise anyone can build your library with some ub-sanitiser,
> get a crash, look at code and publish major "ewwww" about it.

This is a problem with an application, not my library.

By the grace of G-d, my software is good, but it's
not perfect.


Brian

Mr Flibble

unread,
Jul 6, 2020, 5:18:14 PM7/6/20
to
Your fucking god doesn't fucking exist. And yes, I will fucking swear here.

/Flibble

--
"Snakes didn't evolve, instead talking snakes with legs changed into snakes." - Rick C. Hodgin

“You won’t burn in hell. But be nice anyway.” – Ricky Gervais

“I see Atheists are fighting and killing each other again, over who doesn’t believe in any God the most. Oh, no..wait.. that never happens.” – Ricky Gervais

"Suppose it's all true, and you walk up to the pearly gates, and are confronted by God," Byrne asked on his show The Meaning of Life. "What will Stephen Fry say to him, her, or it?"
"I'd say, bone cancer in children? What's that about?" Fry replied.
"How dare you? How dare you create a world to which there is such misery that is not our fault. It's not right, it's utterly, utterly evil."
"Why should I respect a capricious, mean-minded, stupid God who creates a world that is so full of injustice and pain. That's what I would say."

woodb...@gmail.com

unread,
Jul 6, 2020, 5:26:27 PM7/6/20
to
On Monday, July 6, 2020 at 4:18:14 PM UTC-5, Mr Flibble wrote:

Don't swear here, please.


Brian

Öö Tiib

unread,
Jul 6, 2020, 6:02:57 PM7/6/20
to
On Monday, 6 July 2020 21:40:47 UTC+3, woodb...@gmail.com wrote:
> On Monday, July 6, 2020 at 10:15:52 AM UTC-5, Öö Tiib wrote:
> >
> > If you need your cmwRequest object to be built in multiple steps
> > then implement such steps, perhaps even add a debug member that
> > indicates and allows to check its ripeness in debug builds. Do
> > not try to cheat pointlessly with confusing and illegal tricks.
> > Otherwise anyone can build your library with some ub-sanitiser,
> > get a crash, look at code and publish major "ewwww" about it.
>
> This is a problem with an application, not my library.

I do not really know precise architecture of your software, what is
application, what is library what is may be just some helper tool,
sorry. The "cmwRequest" did sound like something that can be neccessary
part of your serialisation system. People who decide things in
business often understand far less than me.

>
> By the grace of G-d, my software is good, but it's
> not perfect.

Oh "perfect" is impossible. It is usually said about something that
is significantly more expensive and insignificantly better than
"good". Avoiding undefined behaviors in portable code however is
necessary to achieve "not bad" level.

red floyd

unread,
Jul 6, 2020, 6:03:12 PM7/6/20
to
Fuck off trying to impose your view of morality on everyone else.

Keith Thompson

unread,
Jul 6, 2020, 6:55:13 PM7/6/20
to
woodb...@gmail.com writes:
> On Monday, July 6, 2020 at 4:18:14 PM UTC-5, Mr Flibble wrote:
> Don't swear here, please.

Don't feed the trolls, please.

--
Keith Thompson (The_Other_Keith) Keith.S.T...@gmail.com
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */

Ian Collins

unread,
Jul 7, 2020, 1:58:34 AM7/7/20
to
On 07/07/2020 10:55, Keith Thompson wrote:
> woodb...@gmail.com writes:
>> On Monday, July 6, 2020 at 4:18:14 PM UTC-5, Mr Flibble wrote:
>> Don't swear here, please.
>
> Don't feed the trolls, please.

Which one?

--
Ian.

Keith Thompson

unread,
Jul 7, 2020, 2:37:42 AM7/7/20
to
Any of them.

Mr Flibble

unread,
Jul 7, 2020, 1:36:31 PM7/7/20
to
On 07/07/2020 07:37, Keith Thompson wrote:
> Ian Collins <ian-...@hotmail.com> writes:
>> On 07/07/2020 10:55, Keith Thompson wrote:
>>> woodb...@gmail.com writes:
>>>> On Monday, July 6, 2020 at 4:18:14 PM UTC-5, Mr Flibble wrote:
>>>> Don't swear here, please.
>>>
>>> Don't feed the trolls, please.
>>
>> Which one?
>
> Any of them.
There is only one homophobic misogynistic religious bigot in this thread. He is probably a racist Trump supporter too.

woodb...@gmail.com

unread,
Jul 7, 2020, 8:55:15 PM7/7/20
to
On Tuesday, July 7, 2020 at 12:36:31 PM UTC-5, Mr Flibble wrote:
> On 07/07/2020 07:37, Keith Thompson wrote:

> > Any of them.
> There is only one homophobic misogynistic religious bigot in this thread. He is probably a racist Trump supporter too.
>

Not me. And I'd be a Trump supporter if I had to
choose between him and Biden. Thankfully there are
other options.


Brian

Chris M. Thomasson

unread,
Jul 7, 2020, 8:57:01 PM7/7/20
to
Holy Moly! One vs the Other. Well, thats fair. ;^)

David Brown

unread,
Jul 8, 2020, 3:41:32 AM7/8/20
to
Again - /please/ stop feeding the trolls - both of them. (And you are
quickly joining that category.)

Both Brian and Mr. Flibble are capable of making sensible, on-topic
posts and contributing to the group. When they do that, by all means
join in.

But when they get together, they both write things that are clearly and
intentionally provocative, offensive, and non-productive. When they do
that, they are trolling. Do not encourage it.

I am, more than some regulars, quite happy with the occasional off-topic
thread in a technical group. But it must be /occasional/, interesting,
informative, enjoyed by many, and in its own thread that does not spoil
a technical thread. This thread does not fit on any count.

If Brian and Mr. Flibble want to fight, let them do it in private - both
their email addresses are accessible.

And if you want to respond to this (other than by simply not posting
more encouragement to such threads), you have my email address.

Chris M. Thomasson

unread,
Jul 15, 2020, 1:35:18 AM7/15/20
to
On 7/8/2020 12:41 AM, David Brown wrote:
> On 08/07/2020 02:56, Chris M. Thomasson wrote:
>> On 7/7/2020 5:55 PM, woodb...@gmail.com wrote:
>>> On Tuesday, July 7, 2020 at 12:36:31 PM UTC-5, Mr Flibble wrote:
>>>> On 07/07/2020 07:37, Keith Thompson wrote:
>>>
>>>>> Any of them.
>>>>    There is only one homophobic misogynistic religious bigot in this
>>>> thread. He is probably a racist Trump supporter too.
>>>>
>>>
>>> Not me.  And I'd be a Trump supporter if I had to
>>> choose between him and Biden.  Thankfully there are
>>> other options.
>>
>> Holy Moly! One vs the Other. Well, thats fair. ;^)
>
> Again - /please/ stop feeding the trolls - both of them. (And you are
> quickly joining that category.)
[...]

Damn.

Brian Wood

unread,
Nov 29, 2020, 9:59:59 PM11/29/20
to
This is what I've come up with to address the UB:
https://github.com/Ebenezer-group/onwards/commit/ed35386a1732a193638ba49648300cfce106edfe

Does it look like an improvement? Tia.


Brian
Ebenezer Enterprises
https://webEbenezer.net

Brian Wood

unread,
Dec 2, 2020, 9:54:18 AM12/2/20
to
Can I get a witness?

Öö Tiib

unread,
Dec 4, 2020, 6:26:23 PM12/4/20
to
Yes. There are no placement new that you originally asked about
so problem solved?

You seem to indent some lines with tabs and some lines with
spaces. That sometimes makes code to look odd in some tools
but if you do not use such tools then it does not matter.


Brian Wood

unread,
Dec 8, 2020, 7:33:50 PM12/8/20
to
There's one placement new left and it's a pain to
get rid of. Undoubtedly, some won't like my latest
commit, where I ditch unique_ptr:

https://github.com/Ebenezer-group/onwards/commit/c08c0fce367dc01462b5a16d7799b6ecff5f3393

But it allows me to not include <memory> and the binary is
over 1% smaller as a result.

>
> You seem to indent some lines with tabs and some lines with
> spaces. That sometimes makes code to look odd in some tools
> but if you do not use such tools then it does not matter.

The tabs were a mistake. I've removed them now.


Brian
Ebenezer Enterprises
0 new messages