mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Safer seed of rand with WASM.
This commit is contained in:
@@ -72,8 +72,9 @@ macro uint hash(value) @local
|
||||
return fnv32a::encode(&&bitcast(value, char[$sizeof(value)]));
|
||||
}
|
||||
|
||||
fn char[8 * 4] entropy()
|
||||
fn char[8 * 4] entropy() @if(!env::WASM_NOLIBC)
|
||||
{
|
||||
|
||||
void* addr = malloc(1);
|
||||
free(addr);
|
||||
static uint random_int;
|
||||
@@ -89,4 +90,16 @@ fn char[8 * 4] entropy()
|
||||
hash(allocator::heap())
|
||||
};
|
||||
return bitcast(entropy_data, char[8 * 4]);
|
||||
}
|
||||
|
||||
fn char[8 * 4] entropy() @if(env::WASM_NOLIBC)
|
||||
{
|
||||
static uint random_int;
|
||||
random_int += 0xedf19156;
|
||||
uint[8] entropy_data = {
|
||||
hash($$TIME),
|
||||
hash(&entropy),
|
||||
random_int,
|
||||
};
|
||||
return bitcast(entropy_data, char[8 * 4]);
|
||||
}
|
||||
@@ -56,6 +56,7 @@
|
||||
- Fix bug when passing a type as a compile time value.
|
||||
- Fix bug due to enum associated values not being checked for liveness.
|
||||
- Regression when compile time accessing a union field not last assigned to.
|
||||
- Safer seed of rand() for WASM without libc.
|
||||
|
||||
### Stdlib changes
|
||||
- Additional init functions for hashmap.
|
||||
|
||||
Reference in New Issue
Block a user