From 2d5b4683e912d6e6e1f1e2ca5aa0297beb3e6807 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 3 Jan 2018 15:11:33 +0100 Subject: Add portable pseudo-random number generator based on the lrand48 family. --- source/fitz/context.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'source/fitz/context.c') diff --git a/source/fitz/context.c b/source/fitz/context.c index f4ebdc98..67fef05b 100644 --- a/source/fitz/context.c +++ b/source/fitz/context.c @@ -3,6 +3,7 @@ #include #include #include +#include struct fz_id_context_s { @@ -132,6 +133,22 @@ void fz_tune_image_scale(fz_context *ctx, fz_tune_image_scale_fn *image_scale, v ctx->tuning->image_scale_arg = arg; } +static void fz_init_random_context(fz_context *ctx) +{ + if (!ctx) + return; + + ctx->seed48[0] = 0; + ctx->seed48[1] = 0; + ctx->seed48[2] = 0; + ctx->seed48[3] = 0xe66d; + ctx->seed48[4] = 0xdeec; + ctx->seed48[5] = 0x5; + ctx->seed48[6] = 0xb; + + fz_srand48(ctx, (uint32_t)time(NULL)); +} + void fz_drop_context(fz_context *ctx) { @@ -250,6 +267,7 @@ fz_new_context_imp(const fz_alloc_context *alloc, const fz_locks_context *locks, fz_new_document_handler_context(ctx); fz_new_style_context(ctx); fz_new_tuning_context(ctx); + fz_init_random_context(ctx); } fz_catch(ctx) { @@ -304,6 +322,7 @@ fz_clone_context_internal(fz_context *ctx) new_ctx->id = fz_keep_id_context(new_ctx); new_ctx->tuning = ctx->tuning; new_ctx->tuning = fz_keep_tuning_context(new_ctx); + memcpy(new_ctx->seed48, ctx->seed48, sizeof ctx->seed48); new_ctx->handler = ctx->handler; new_ctx->handler = fz_keep_document_handler_context(new_ctx); -- cgit v1.2.3