@vaporeon_ I don't know what this is doing but it looks evil:
const char* seed = "random seed";
RAND_seed(seed, sizeof(seed));
The following snippet which assigns to an rvalue, something you're not supposed to be able to do:
#include <iostream>
class A{};
int main() {
const A a;
std::cout << &(A() = a) << "\n";
}
using the ternary operator to conditionally change what variable is assigned to:
int main() {
int a;
int b;
// do stuff, also assign to a and b
(a < b ? a : b) = 3;
}
The following is actually valid C++ code:
https://www.google.com
Operator overloading lets you do plenty of absurdities. You could, for example, override <= such that it behaves like a "move assignment":
class A {
public:
int num;
A& operator<=(A& other) {
this->num = other.num;
return *this;
}
};
int main() {
A a;
A a2;
a.num = 1000;
a2 <= a; // move a's content to a2
};
There's certainly more but this is plenty of evil shit.
@wallhackio I think the ternary operator thing is actually super cool
It's something that I sometimes wish to do in C, but it's less convenient there, I have to do an if-statement
@vaporeon_ (tbh i also kinda like it)
@wallhackio How is the Google URL valid code?
$ echo https://www.google.com > test.cpp
$ g++ test.cpp
test.cpp:1:1: error: 'https' does not name a type
1 | https://www.google.com
| ^~~~~
@vaporeon_ i must be misremembering what i saw. i'm trying to find it but i can't. for now just forget about that one
@vaporeon_ maybe it needs to be in the main function
@wallhackio Yeah, that works!! I'm delighted by this
@wallhackio It's also valid C code
@vaporeon_ lmao
@wallhackio Is the RAND_seed thing:
const char* seed = "random seed";
RAND_seed(seed, sizeof(seed));
Is this similar to how you can cat > /dev/random
and then write whatever bytes there to seed the randomness pool? NetBSD made me do that on a device that didn't have sufficient hardware to generate randomness on its own...
Though: I thought sizeof(seed)
should just return sizeof(const char*)
and not the length of the string. Unless this is some extremely cursed C++ thing...
@vaporeon_ you have already put more thought into that hack than i ever have by writing this comment
@wallhackio Where's that RAND_seed
macro defined? Is it part of C++ itself or is it part of your code base?
@vaporeon_ it's from an openssl library: https://docs.openssl.org/1.0.2/man3/rand/
@wallhackio @vaporeon_ “an openssl library”
@aescling @wallhackio @vaporeon_ Let's be honest, that's much more correct phrasing than it has any right to be.
@aschmitz @aescling @vaporeon_ today you are my favorite masto user who username's first syllable sounds like "ash"
@vaporeon_ @aescling @wallhackio @aschmitz oddly specific
@wallhackio @aschmitz @vaporeon_ banned.
@aescling @vaporeon_ forgive me for not knowing what i am talking about
@aescling @vaporeon_ lmao
@wallhackio So the second argument is indeed supposed to be the number of bytes in your arguments (i.e. strlen(seed)
)... I think the programmer made a mistake here, since sizeof(seed)
will just return the size of a const char*
on your architecture:
#include <stdio.h>
int main() {
const char* seed = "random seed";
printf("%zu\n", sizeof(seed)); /*will print 8 on 64-bit computer */
}
@vaporeon_ someone in a reddit comment said they actually saw this in their company's production code so even if its wrong, its out in the wild somewhere
@wallhackio So they're really out there seeding their random number generator with the very predictable string "random seed"
...? That's really bad...
@vaporeon_ did you know that in C++, there are six different ways to inherit a class
@wallhackio @vaporeon_ marriage, inheritance, corporate takeover....
@vaporeon_ you can either inherit something publicly, privately, or protectedly
furthermore, there is virtual or nonvirtual inheritance
so there is private virtual
, private
, protected virtual
, protected
, public virtual
, and public
inheritance
@vaporeon_ no one uses anything other that public
inheritance but the other five are there so that you can demonstrate knowledge of language trivia during a job interview
@wallhackio @vaporeon_ lmao
@vaporeon_ the default type of inheritance is private
inheritance even though no one ever uses it
very well-designed language
@vaporeon_ According to the standard, every expression belongs to exactly one of the fundamental classifications lvalue, xvalue, or prvalue.
A prvalue is an expression that 1) when evaluated, initializes an object, or 2) computes the value of an operand of an operator, as specified by the context in which it appears, or 3) has type cv void
.
An expression is an xvalue if it is 1) a move-eligible id-expression, 2) the result of calling a function, implicitly or explicitly, whose return type is an rvalue reference to object type, 3) a cast to an rvalue reference to object type, 4) a subscripting operation with an xvalue array operand, 5) a class member access expression designating a non-static data member of non-reference type in which the object expression is an xvalue, or 6) a .*
pointer-to-member expression in which the first operand is an xvalue and the second operand is a pointer to data member.
An expression is an lvalue if it satisfies both of the following conditions: 1) it is not an xvalue, and 2) its evaluation determines the identity of an object or function.
I don't think there is a human being on the planet who understands every detail of these definitions.
@wallhackio C++ rage comic where Vaporeon can't handle C++ sounds fun to draw
Send me some awful C++ constructs for inspiration