mirror of
https://github.com/transmission/transmission.git
synced 2026-05-04 07:35:08 +01:00
refactor: add tr_rand_obj() (#4238)
* refactor: add tr_rand_obj() There are a lot of places in the codebase where we need to populate an integral type or a fixed-size array with random data. To do this, we instantiate a local on the stack, fill it with tr_rand_buffer(), and then use it. This PR creates a helper function to make this a one-liner.
This commit is contained in:
@@ -104,6 +104,14 @@ void tr_x509_cert_free(tr_x509_cert_t handle);
|
||||
*/
|
||||
bool tr_rand_buffer(void* buffer, size_t length);
|
||||
|
||||
template<typename T>
|
||||
T tr_rand_obj()
|
||||
{
|
||||
auto t = T{};
|
||||
tr_rand_buffer(&t, sizeof(T));
|
||||
return t;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Generate a SSHA password from its plaintext source.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user