MEM: support overaligned types in MEM_cnew_array #120632
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#120632
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "JacquesLucke/blender:cnew-array-alignment"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This is similar to the recent change for
MEM_cnew
:60a3d85b88
.A new function called
MEM_calloc_arrayN_aligned
is added that is used by bothcnew
functions now.@blender-bot build
@ -305,0 +311,4 @@
if (alignof(T) <= MEM_MIN_CPP_ALIGNMENT) {
return static_cast<T *>(MEM_calloc_arrayN(length, sizeof(T), allocation_name));
}
const size_t bytes_num = length * sizeof(T);
The allocator needs to be consistently robust against the integer overflow on allocation vector of attack, so it needs to be using
MEM_size_safe_multiply()
.Using
MEM_size_safe_multiply
was a bit more annoying than expected because it was a private inline function and couldn't easily be included in the public header (also because it usesMEM_INLINE
andUNLIKELY
which are private to the allocator). Instead I added a newMEM_calloc_arrayN_aligned
which is implemented inmallocn.cc
which is then called by the C++ functions.@blender-bot build
I think having
MEM_calloc_arrayN_aligned
is useful regardless, so it is probably a better way of achieving the proper multiplication check. There are couple of inlined comments.@ -303,2 +313,4 @@
}
/**
* Same as MEM_cnew but for arrays, better alternative to #MEM_calloc_arrayN.
The function can now be moved back below
MEM_cnew()
, so that the comment does not refer to a function which is not yet "known" ? Also makes diff smaller?@ -104,0 +109,4 @@
{
size_t bytes_num;
if (UNLIKELY(!MEM_size_safe_multiply(len, size, &bytes_num))) {
abort();
The other functions do error print like
which could be useful for troubleshooting.
Looks like that means that I'll have to duplicate the implementation of the
MEM_calloc_arrayN_aligned
function becauseprint_error
is a separate function for the lockfree and guarded allocator :(What a fun experience :(
Maybe
fprintf(stderr, "Calloc array aborted due to integer overflow\n");
will do it for now ? :)I just split it up into a lockfree and guarded implementation.
@ -104,0 +110,4 @@
size_t bytes_num;
if (UNLIKELY(!MEM_size_safe_multiply(len, size, &bytes_num))) {
abort();
return NULL;
return nullptr;
@blender-bot build
On a code side seems fine. Could be good to give Windows another retrial. The Internal Compiler Error is unlikely to be caused by this specific fix =\
@blender-bot build windows