Skip to content

Commit 2e45f61

Browse files
committed
sysstr: fix (new) cast bug for old strings
1 parent 9f9cb27 commit 2e45f61

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ errors.
3434
to more efficiently calculate the symmetric difference of bitsets.
3535
- `strutils.multiReplace` overload for character set replacements in a single pass.
3636
Useful for string sanitation. Follows existing multiReplace semantics.
37-
- `system.setLenUninit` for the `string` type. Allows setting length without initializing new memory on growth.
3837

3938
- `std/files` adds:
4039
- Exports `CopyFlag` enum and `FilePermission` type for fine-grained control of file operations
@@ -51,6 +50,7 @@ errors.
5150
- `copyDirWithPermissions` to recursively preserve attributes
5251

5352
- `system.setLenUninit` now supports refc, JS and VM backends.
53+
- `system.setLenUninit` for the `string` type. Allows setting length without initializing new memory on growth.
5454

5555
[//]: # "Changes:"
5656

lib/system/sysstr.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ proc setLengthStr(s: NimString, newLen: int): NimString {.compilerRtl.} =
232232
proc setLengthStrUninit(s: var string, newlen: Natural) {.nodestroy.} =
233233
## Sets the `s` length to `newlen` without zeroing memory on growth.
234234
## Terminating zero for cstring compatibility is set.
235-
var str = cast[NimString](s.unsafeAddr)
235+
var str = cast[NimString](s)
236236
let n = max(newLen, 0)
237237
if str == nil:
238238
if n == 0: return

tests/stdlib/tstring.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ proc main() =
122122

123123
block: # setLen #setLenUninit
124124
proc checkStrInternals(s: string; expectedLen: int) =
125-
doAssert s.len == expectedLen
125+
doAssert s.len == expectedLen, "expected:" & $expectedLen & " s.len:" & $s.len
126126
when nimvm: discard
127127
else:
128128
when defined(UncheckedArray): # skip JS

0 commit comments

Comments
 (0)