« first day (2800 days earlier)      last day (2373 days later) » 

00:31
std::accumulate is poorly designed because the return type is the same type as the input. This has an obvious problem with overflow, especially on small types like uin8/uint16
just feed it an init value of a larger type then?
@Mikhail What other type should it be? If you want it to be a bigger type, ensure the type of the initial value is said bigger type: std::accumulate(begin, end, static_cast<std::uint32_t>(uint8_value));
(it doesn't care about the type of the individual elements in the range, but it does care about the init value)
yeah fuck
I say unary plus it and let the numerical gods take the wheel
I need a consistent parameter name for a step function, what works well? e.g. 'I stepped 3 paces/places/meters forward'
'I stepped 3 steps forward' seems a little bit silly
00:36
std::next
I stepped 3 std::next forward and found myself at the same place
What do you use accumulate for apart from calculating sum?
the average :-)
And that :)
So, Qt has a special += fast string building mode when a certain header is included. I used accumulate to build that kind of string.
 
2 hours later…
02:22
No one should be required to use qsort in C++... — Borgleader 6 secs ago
sigh
Just a heads up to everyone. I'm gonna be writing a blog over the weekend about the potential AVX Spectre vulnerability. It won't be complete with a proof-of-concept since that's out of my area. But I feel enough of the pieces have fallen into place that it might be a viable exploit.
At the very least, it should get some "real" experts to finish up the theory with a proof-of-concept. Like all the other Spectre variants, it's difficult to exploit so the Intel bug bounty is low and not really worth my time. So I'm just gonna publish the theory as is on my website whenever I finish it.
I might drop a link here prior to release if anyone wants to proofread it for obvious issues.
Ell
Ell
02:42
@LucDanton I stepped 3 hops forward? maybe? it's a difficult one
that's not a bad one, for now I’ve settled on 'places' which is similar
::step(const int steps
Can’t be done. qsort uses memcpy to copy objects, so the type that you’re sorting must be trivially copyable. std::string is not trivially copyable, so objects that hold strings are also not trivially copyable. — Pete Becker 4 mins ago
Hah, I forgot about that
^ can't come up with a scenario where this will cause a problem.
Also literally the tutorial from: geeksforgeeks.org/comparator-function-of-qsort-in-c
03:15
ah well with an endorsement like that
03:36
My attempt to rep whore was frustrated by the poor quality of OP's question.
03:54
isn't that always the way
you come up with a wonderful answer that they might actually understand, and you put comments on it, and you describe the reasons everything works
and then the question is closed as off topic, because "HELP ME STACK OVERFLOW CODE GENIUSES HOMEWORK DUE IN THREE HOURS I HAVE printf("hello world");" is not a complete question, and does not explain what is wrong.
so you post it as a comment because you may as well
and then you realize oh,
whoops
that was heavy iterator use with the algorithms library, with some light template metaprogramming mixed in
and oh dear, where did all the comments go
:3
and the OP goes, "what is this plox hlep"
so naturally you link it again, say it's self-explanatory, and never respond to further inquiries.
I mean
uh
I wouldn't do that
of course not
providing an answer they have no hope of understanding in the most confusing way possible so that they have no way of passing it off as their own work is certainly not my favorite way of responding to help vampires
that would be a deeply immature waste of time
04:16
ah, well
it's not like I've been active to be an immature jerk on SO in quite some time
my last comment was in February
04:29
I'm just really bored, worked like 12 hours, everything I did today worked, but everybody is out of town.
get drunk, make weird commits
way ahead of you ( ͡° ͜ʖ ͡°)
@jaggedSpire Look at these people butt hurt about somebody using qsort stackoverflow.com/a/50884598/314290
hm
that's pretty weird to think about, since you're messing about in a way that sort of circumvents C++ object lifetime handling
feels very much like playing with lit dynamite
04:46
More like their opinions come from the "best practices" cargo cult
@jaggedSpire the danger is doing it the other way around
@LucDanton getting drunk after making weird commits, or getting weird and making drunk commits?
getting committed and making weird drinks of course
ah, of course
the fourth classic mistake of warfare
05:19
@Mikhail coliru
 
2 hours later…
07:29
Swapped the crowing rooster with a new hen ... didn't go well at the start, the only cockerel left is acting all aggressive towards the new hen. But inside, he's feeling afraid.
08:18
@jaggedSpire Compiled that on my local machine, no core dump. GCC or MSVC 2017.
That's a borderline bug, because the memory protection tools assumed a behavior that is perhaps too strict.
Let's see what kind of shit I get for this when I wake up tomorrow:
I just finished writing a blog on a (theoretical) new #Spectre exploit variant for @Intel processors involving #AVX and #AVX512 instructions. Should I piss off the world and just publish it? Or should I do the right thing and give it to Intel first? Severity 6.0 via CVSS 3.0.
3am, time to sleep.
My guess is that nobody will give even half a shit.
@Mysticial you fucked it up because there is no link to a blog post
I should stop telling people it is going to be updated soon in my apps, because my apps are generally updated once per few years.
But ... I am going to do it again just for the present one.
I should feel bad, but I generally forget about such things straight away.
@Mikhail This really isn't going to work. SSO for string means self-referring pointers. Self-referring pointers are fixed up by assignment.
Can you come up with a situation where it doesn't work?
08:27
sure
nwp
nwp
I needed a while to figure out why that happens.
@Mikhail Actually, the real fuck up is that I misread the CVSS calculator. It looks like a 4.3 instead of a 6.0. But that'll depend on whether it can considered exploitable over the network. (i.e. through a browser)
@nwp But you realize that there isn't any problem with freeing that address as it actually was allocated, or rather there is no double free happening?
Fuck this, I don't know. Some of the buttons are so sensitive that they affect the stupid score by more than 1.0.
@Mysticial Also wtf are you talking about. If you wrote a blog post you should post the expletive link.
nwp
nwp
08:31
@Mikhail There is. It is calling free on stack memory which of course crashes.
Two strings, SSO'd, "zzzz", "aaaa". memcpy swaps them around. The end content is "aaaa", "zzzz", but the individual string objects point at each other's buffers. So a[0].push_back('b'); will make the other string "zzzzb", while modifying the size of the first string object
congratulations, you broke the invariant
@Mikhail I'm playing with this thing right now: nvd.nist.gov/vuln-metrics/cvss/v3-calculator
In addition, if SSO detects being small by detecting if the pointer is pointing to self, you've caused a delete where it shouldn't be
I have the blog post in front of me, but I need some time to think about it before I post it. Mainly because the bug bounty isn't for Spectre variants isn't quite as small as I thought it was. (but still small) But secondly, I'm not sure I'm ready to face a potential backlash if I disclose without giving Intel and OS's devs any time to do mitigations.
Because that turns it into a zero-day exploit.
all the best~~
nwp
nwp
08:39
Schrödinger bugs are a fun category.
@milleniumbug If you swapped them the pointer to the buffer also changed right? So if a string is, struct {char* data, int length} you'd be fine.
UB bugs are Schrödinger bugs - both there .. and not
14 mins ago, by milleniumbug
In addition, if SSO detects being small by detecting if the pointer is pointing to self, you've caused a delete where it shouldn't be
libstdc++ does this
      bool
      _M_is_local() const
      { return _M_data() == _M_local_data(); }

      // ...

      void
      _M_dispose()
      {
        if (!_M_is_local())
          _M_destroy(_M_allocated_capacity);
      }

      void
      _M_destroy(size_type __size) throw()
      { _Alloc_traits::deallocate(_M_get_allocator(), _M_data(), __size + 1); }
(_M_dispose is called by the destructor)
09:07
I don't quite get it. If if I swap them all, then _M_data() == _M_local_data() evaluates to the expected, true case.
Perhaps the confusion is that I consider std::string to be a two member POD structure.
_M_local_data returns a pointer to a _M_local_buf which is a data member of std::string
its address doesn't change
If you swaped one object over another object, the data member does change?
the contents, but not the address
The string has two members? The pointers swap, and the lengths swap... The only way you get an error if you have some other monitoring framework that can actually keep track of the location of the allocating object, and what it allocated, which is perhaps enforcing an unnecessary level of rigor. This is probably what's happening on these other compilers, but not on my machine, for example.
Please re-read the whole discussion again
You're still not acknowledging existence of short string optimization (SSO)
09:18
Yeah, that might be underlying issue. I don't know what SSO does.
I'll repeat it then
or just paste the relevant part of the libstdc++
      // Use empty-base optimization: cantrip.org/emptyopt.html
      struct _Alloc_hider : allocator_type // TODO check __is_final
      {
        _Alloc_hider(pointer __dat, const _Alloc& __a = _Alloc())
        : allocator_type(__a), _M_p(__dat) { }

        pointer _M_p; // The actual data.
      };

      _Alloc_hider      _M_dataplus;
      size_type         _M_string_length;

      enum { _S_local_capacity = 15 / sizeof(_CharT) };

      union
      {
        _CharT           _M_local_buf[_S_local_capacity + 1];
If pointer points to _M_local_buf, we treat it as a "short string", to avoid the need for using dynamic allocation. If it doesn't, it obviously is pointing to heap allocated memory, so we can delete it.
If you swap all the contents, together with the pointer, the address doesn't point to _M_local_buf, but to other object's _M_local_buf
sample above by @nwp coliru.stacked-crooked.com/a/fe14f54d7770b7bc demonstrates that it does indeed free memory which wasn't dynamically allocated
Ah, i see what you mean. The short vs long string ownership is determined at runtime based on if the pointer is local to the object.
In your case, you've swapped the contents, so the pointer doesn't point to this->_M_local_buf, but it also doesn't point to heap allocated memory
Yeah, I got it. I wasn't aware of this mechanism...
09:39
Hence everyone trying to warn about "not playing with dynamite"
I mean, I don't write code like this. For example, today I implemented a lot of new functionality (new hardware, new settings) and my validation tests passed on the first go. System is shipping out, and everybody is pretty happy. I'm more interested in the underlying reason as to why stuff shouldn't be done.
09:53
@Mikhail std::string isn't anywhere near POD.
It could be. Anyways, the underlying problem here wasn't mentioned by any of the people in the post. One of strings function's, in that implementation determines if the object is short based on the buffer pointer relative to the object.
it certainly can't ever be
the whole user-defined constructors, destructors, etc thing that it must have in order to function in a vaguely sane way?
sane
you can insane it as a POD if you want to, it would just be really awkward and buggy to use at best
probably look like std::basic_string_view
09:59
basic_string_view isn't really remotely as useful or central as std::string
Yeah, I mean you couldn't have dynamically allocated strings that owned a buffer.
Anyways, I need to sleep. Peace.
 
2 hours later…
user406009
11:54
@Mysticial Can't you just give the OS devs warning? I would trust them more than I trust Intel.
12:07
@milleniumbug That's caused by members pointing to other members right? (And the reason some are advocating for a "relocatable" trait.)
@Mysticial Honestly I'd actually give brower makers the warning along with OS devs, as they are the most obviously exploitable place with emscripten and webassembly
 
1 hour later…
13:20
@StackedCrooked Indeed. If you could reliably detect relocatability, this code could have a chance of working
nwp
nwp
It should always work for std::vector<char>.
14:07
has anyone played TIS-100 - do I have to know assembly before playing
14:20
How do I login as root on my iPhone? I can't find any documentation about that.
/s :P
Even though it's my iPhone!
are you serious?
What do you mean?
nwp
nwp
Yes. /s stands for serious.
wasn't 100% sure
@StackedCrooked The thing with relocatable trait is that it's not inferable from a type (therefore doesn't compose), so people will have to specify it for every custom type, which means they'll get it wrong sooner or later. And also specifying it for third-party types too, which is a recipe for disaster.
Also runs counter to C++ standard's intent to not specify implementation details
14:28
So that means it's like "noexcept" or "restrict". There are cases where the user needs to inform the compiler.
They don't necessarily end in disaster.
I don't see why the compiler needs to give a fuck about this
the existing system handles it fine
Is std::vector<char> relocatable? Sure it could be specified to do so. Is std::vector<char>::iterator relocatable? By itself it could be. Is a struct A { std::vector<char> a; std::vector<char>::iterator it; }; relocatable? If it points to a[0], it is certainly not
So better don't use it for that case then.
nwp
nwp
noexcept is arguably a disaster. Specifying that correctly for all functions is just not viable.
Sure, but that disqualifies from inferring "relocatability" automatically
14:31
@StackedCrooked OK, but what actually is the use case for the relocatable trait anyway?
It allows to bypass the copy constructor and use memcpy instead.
well definitely fuck that
In certain contexts.
let the optimiser take care of it at best
I don't know why people have such an erection for memcpying things everywhere, it's just a recipe for disaster
in shit languages that don't have proper copy/move constructors, maybe, but no need in C++
"more memcpy" really isn't a desirable goal at all
The things is that the only thing preventing it is that member pointers sometimes point to other members. Which is fairly rare. So I can see why some engineers are frustrated that they can't do it because of that one corner case.
14:34
uh, no
you can't memcpy a std::string anyway because if it points to heap memory you're gonna get double deletes and stuff
that one corner case doesn't really factor into it
Some people believe that memcpy followed by not calling destructor on the other is faster than move assignment and needing to call the destructor on the other. Now, if they actually managed to benchmark it, then it counts as "risky optimization, but we believe the cost is worth it for our purposes", but IMO it is certainly not something that should belong in C++ standard
if those people really really care they can implement their own system that works that way (and then feel bad as it won't be any faster but will be much more buggy)
Huh, is code review se gone?
Ah. Ok.
Weird. Google didn't find it for "codereview se".
14:38
Google Search seems to get worse and worse every year
(given from what I keep hearing from people)
I became aware of the potential "relocation" benefit when trying to implement a version of std::function that always uses small buffer storage. Since the only member variable is a aligned_storage value it seemed like it would be nice if I could just move the object by value and memset then moved-from storage to zero. (This was my attempt back then.)
But in the end I couldn't do it and it didn't affect my life that much :)
That guideline sounds as if I was told to explicitly noexcept every destructor in case some retard actually manages to a write a class with a noexcept(false) destructor and I happen put it as a member in my class
If you have such a member does it make your destructor noexcept(false) automatically?
14:44
(if I don't explicitly declare noexcept-ness)
@Mysticial Green rep box update. tia
nwp
nwp
@milleniumbug You only do that when it can throw an exception. "Simple" to check.
I'd say typically people won't declare destructors noexcept(false) if they don't intend to throw from them
@milleniumbug Actually I had to work on something where performance actually matters a lot for real. And I found that in that kind of code you don't even consider things like "move constructors". If it really needs to be fast then you end up with plain arrays, pointers and ints.
14:51
(and a presence of a throw or something that indirectly does a throw in a function doesn't affect its noexcept-ness, which for destructors is implicitly noexcept(true))
@StackedCrooked Then it belongs to the "it's a risky optimization, but for us, performance benefits have bigger priority than not having maintenance issues" I'd say
nwp
nwp
I clicked on that and steins-gate.wikia.com/wiki/SERN is the first website I've seen that actually lets you opt out of tracking as easily as opting in.
That's what they want you to believe.
SERN is everywhere.
15:10
That tab control thing could as well fit between "Top questions" and "Ask question"
instead you have two rows with one row of space being wasted
@milleniumbug Well, better submit a user story and hope the product owner adds it to the backlog.
15:52
@StackedCrooked What if I have a stateless function object which has an all-zero representation?
Then you don't implement the relocatable trait.
that is fair enough
but it seems weird to not implement the trait for something that is inherently relocatable
It's an oddball since it can't be decided by the compiler.
Anyway, I don't really care because I don't believe it will make any program significantly faster.
Unless perhaps for a specifically crafted use case.
16:08
@Borgleader wut, still looks the same for me.
@Lalaland I don't think it's fixable entirely software without disabling AVX/AVX512 completely at the OS-level. I don't know if it can be fixed in microcode.
16:21
@Mysticial No, I was asking for an update on your green rep box :P
@Borgleader Find me an "amazing" question first. :)
16:45
<https://stackoverflow.com/q/50889660/583833>
does Community delete your posts when you nuke your account or did the account and the post get nuked by Community?
I need other images
@Mysticial P.S:
How can you resist the temptation to not click that +3903 shiny green notif? — Frakcool Jun 12 at 20:45
that screenshot would probably make their head explode xD
17:25
@milleniumbug Sounds more like one needs a way to specify some variables as already destructed when passed to a function that will destroy what is passed in. Would only work for local variables though
posted on June 16, 2018 by Scott Meyers

Until today, this blog has been about "Scott Meyers' Professional Activities and Interests." I've just removed the "Professional," so now the blog is about "Scott Meyers' Activities and Interests." In theory, this means I can now blog about anything, though in practice, you're unlikely to notice much change. I'm not planning anything dramatic. In fact, I'm not planning anything at all. I just t

@Borgleader haha
 
3 hours later…
20:14
Should I get this one amazon.ca/Programming-Principles-Practice-Using-2nd/dp/… after finishing Accelerated C++?
20:56
No. You can find "samples" of most books online.
 
2 hours later…
23:08
Drones and chickens are sort of opposite in some kind of ways - chickens are birds, but can not fly. Drones are not birds, but can fly.
That's why I have 2 chickens and 2 working drones </trollololo>
tie them together and you have a breeding pair of the perfect being
23:29
Do not speaking of breeding pair, I am ashamed of my only cockerel left - he's the most naggy rooster I have known of, constantly saying things, and constantly trying to look bigger by tilting his body and extend his wing when close to the new hen. But every time I try to catch him, he will scream murder ... but never hesitate to eat any food I give him.
lil bastard

« first day (2800 days earlier)      last day (2373 days later) »