From 37c6a51a519d46e7e3bf1ea7b3f744ffa25e9c28 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 2 May 2025 17:17:58 -0400 Subject: Initialize random seed for tomo compiler itself --- src/tomo.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/tomo.c b/src/tomo.c index e4da0515..c8e2fa70 100644 --- a/src/tomo.c +++ b/src/tomo.c @@ -9,6 +9,9 @@ #include #include #include +#if defined(__linux__) +#include +#endif #include "ast.h" #include "compile.h" @@ -23,6 +26,7 @@ #include "stdlib/paths.h" #include "stdlib/print.h" #include "stdlib/random.h" +#include "stdlib/siphash.h" #include "stdlib/text.h" #include "typecheck.h" #include "types.h" @@ -131,6 +135,14 @@ int main(int argc, char *argv[]) if (getenv("NO_COLOR") && getenv("NO_COLOR")[0] != '\0') USE_COLOR = false; +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) + arc4random_buf(TOMO_HASH_KEY, sizeof(TOMO_HASH_KEY), 0); +#elif defined(__linux__) + getrandom(TOMO_HASH_KEY, sizeof(TOMO_HASH_KEY), 0); +#else + #error "Unsupported platform for secure random number generation" +#endif + // Set up environment variables: const char *PATH = getenv("PATH"); setenv("PATH", PATH ? String(TOMO_PREFIX"/bin:", PATH) : TOMO_PREFIX"/bin", 1); @@ -361,7 +373,7 @@ static void _compile_statement_header_for_library(libheader_info_t *info, ast_t return; Path_t path = Path$from_str(use->path); - if (!Table$get(*info->used_imports, &path, Table$info(&Path$info, &Path$info))) { + if (!Table$has_value(*info->used_imports, path, Table$info(&Path$info, &Void$info))) { Table$set(info->used_imports, &path, NULL, Table$info(&Text$info, &Void$info)); CORD_put(compile_statement_type_header(info->env, info->header_path, ast), info->output); CORD_put(compile_statement_namespace_header(info->env, info->header_path, ast), info->output); -- cgit v1.2.3