Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

follow up #22380; fixes incorrect usages of newWideCString #23278

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/pure/os.nim
Original file line number Diff line number Diff line change
Expand Up @@ -424,13 +424,13 @@ proc expandFilename*(filename: string): string {.rtl, extern: "nos$1",
when defined(windows):
var bufsize = MAX_PATH.int32
var unused: WideCString = nil
var res = newWideCString("", bufsize)
var res = newWideCString(bufsize)
while true:
var L = getFullPathNameW(newWideCString(filename), bufsize, res, unused)
if L == 0'i32:
raiseOSError(osLastError(), filename)
elif L > bufsize:
res = newWideCString("", L)
res = newWideCString(L)
bufsize = L
else:
result = res$L
Expand Down
4 changes: 2 additions & 2 deletions lib/std/private/ospaths2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -862,13 +862,13 @@ when not defined(nimscript):
raiseAssert "use -d:nodejs to have `getCurrentDir` defined"
elif defined(windows):
var bufsize = MAX_PATH.int32
var res = newWideCString("", bufsize)
var res = newWideCString(bufsize)
while true:
var L = getCurrentDirectoryW(bufsize, res)
if L == 0'i32:
raiseOSError(osLastError())
elif L > bufsize:
res = newWideCString("", L)
res = newWideCString(L)
bufsize = L
else:
result = res$L
Expand Down
2 changes: 1 addition & 1 deletion lib/std/syncio.nim
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ proc readLine*(f: File, line: var string): bool {.tags: [ReadIOEffect],
if f.isatty:
const numberOfCharsToRead = 2048
var numberOfCharsRead = 0'i32
var buffer = newWideCString("", numberOfCharsToRead)
var buffer = newWideCString(numberOfCharsToRead)
if readConsole(getOsFileHandle(f), addr(buffer[0]),
numberOfCharsToRead, addr(numberOfCharsRead), nil) == 0:
var error = getLastError()
Expand Down
1 change: 1 addition & 0 deletions lib/std/widestrs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ when not (defined(cpu16) or defined(cpu8)):
createWide(result, size * 2 + 2)

proc newWideCString*(source: cstring, L: int): WideCStringObj =
## Warning:: `source` needs to be preallocated with the length `L`
createWide(result, L * 2 + 2)
var d = 0
for ch in runes(source, L):
Expand Down
Loading