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
@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));
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.
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 Becker4 mins ago
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
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.
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.
@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)
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
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.
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.
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
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.
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.
@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
@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
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
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.
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)
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
@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.
(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
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.
@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.
<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?
@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
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…
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.