mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-15 07:43:26 +00:00
orc: fix overflow checking regression (#25089)
Raising exceptions halfway through a memory allocation is undefined
behavior since exceptions themselves require multiple allocations and
the allocator functions are not reentrant.
It is of course also expensive performance-wise to introduce lots of
exception-raising code everywhere since it breaks many optimisations and
bloats the code.
Finally, performing pointer arithmetic with signed integers is incorrect
for example on on a 32-bit systems that allows up to 3gb of address
space for applications (large address extensions) and unnecessary
elsewhere - broadly, stuff inside the memory allocator is generated by
the compiler or controlled by the standard library meaning that
applications should not be forced to pay this price.
If we wanted to check for overflow, the right way would be in the
initial allocation location where both the size and count of objects is
known.
The code is updated to use the same arithmetic operator style as for
refc with unchecked operations rather than disabling overflow checking
wholesale in the allocator module - there are reasons for both, but
going with the existing flow seems like an easier place to start.
(cherry picked from commit 8b9972c8b6)
This commit is contained in:
@@ -1043,15 +1043,6 @@ proc toDecimal64*(ieeeSignificand: uint64; ieeeExponent: uint64): FloatingDecima
|
||||
# ToChars
|
||||
# ==================================================================================================
|
||||
|
||||
when false:
|
||||
template `+!`(x: cstring; offset: int): cstring = cast[cstring](cast[uint](x) + uint(offset))
|
||||
|
||||
template dec(x: cstring; offset=1) = x = cast[cstring](cast[uint](x) - uint(offset))
|
||||
template inc(x: cstring; offset=1) = x = cast[cstring](cast[uint](x) + uint(offset))
|
||||
|
||||
proc memset(x: cstring; ch: char; L: int) {.importc, nodecl.}
|
||||
proc memmove(a, b: cstring; L: int) {.importc, nodecl.}
|
||||
|
||||
proc utoa8DigitsSkipTrailingZeros*(buf: var openArray[char]; pos: int; digits: uint32): int {.inline.} =
|
||||
dragonbox_Assert(digits >= 1)
|
||||
dragonbox_Assert(digits <= 99999999'u32)
|
||||
|
||||
Reference in New Issue
Block a user