From 4041cc06d5a0327c6d6d7e0bdec8516df06cb5ba Mon Sep 17 00:00:00 2001 From: Ryan Liptak Date: Fri, 31 Jan 2025 02:04:02 -0800 Subject: [PATCH] Allocator/Random: document that comparing `ptr` may result in illegal behavior See #21756 and #17704 --- lib/std/Random.zig | 3 +++ lib/std/mem/Allocator.zig | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/std/Random.zig b/lib/std/Random.zig index 8c68bdf6daefd39efedca50bf9719a18331d76b4..ae88d8b4fe7fc3c045da53feaf392f86eecc52b4 100644 --- a/lib/std/Random.zig +++ b/lib/std/Random.zig @@ -29,6 +29,9 @@ pub const RomuTrio = @import("Random/RomuTrio.zig"); pub const SplitMix64 = @import("Random/SplitMix64.zig"); pub const ziggurat = @import("Random/ziggurat.zig"); +/// Any comparison of this field may result in illegal behavior, since it may be set to +/// `undefined` in cases where the random implementation does not have any associated +/// state. ptr: *anyopaque, fillFn: *const fn (ptr: *anyopaque, buf: []u8) void, diff --git a/lib/std/mem/Allocator.zig b/lib/std/mem/Allocator.zig index 7cf201d4b169d313dd7ad9f8abb38fb106e97c48..bc3ef028b9130f5076a0699e152ab13b4c5faba0 100644 --- a/lib/std/mem/Allocator.zig +++ b/lib/std/mem/Allocator.zig @@ -10,7 +10,10 @@ const builtin = @import("builtin"); pub const Error = error{OutOfMemory}; pub const Log2Align = math.Log2Int(usize); -// The type erased pointer to the allocator implementation +/// The type erased pointer to the allocator implementation. +/// Any comparison of this field may result in illegal behavior, since it may be set to +/// `undefined` in cases where the allocator implementation does not have any associated +/// state. ptr: *anyopaque, vtable: *const VTable, -- 2.54.0