Skip to content

Commit

Permalink
follow up #22380; fixes incorrect usages of newWideCString (#23278)
Browse files Browse the repository at this point in the history
follow up #22380
  • Loading branch information
ringabout authored Feb 5, 2024
1 parent dd753b3 commit a1d8203
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
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

0 comments on commit a1d8203

Please sign in to comment.