fixes some strictdefs warnings (#24502)

This commit is contained in:
ringabout
2024-12-04 18:28:13 +08:00
committed by GitHub
parent c3120b6121
commit 8f4bfda5f4
19 changed files with 44 additions and 15 deletions

View File

@@ -10,8 +10,8 @@ type Cell* = object
iterator parseTableCells*(s: string, delim = '\t'): Cell =
## Iterates over all cells in a `delim`-delimited `s`, after a 1st
## pass that computes number of rows, columns, and width of each column.
var widths: seq[int]
var cell: Cell
var widths: seq[int] = @[]
var cell: Cell = Cell()
template update() =
if widths.len<=cell.col:
widths.setLen cell.col+1
@@ -73,6 +73,7 @@ proc alignTable*(s: string, delim = '\t', fill = ' ', sep = " "): string =
## to a width that's computed for each column; consecutive columns are
## delimited by `sep`, and alignment space is filled using `fill`.
## More customized formatting can be done by calling `parseTableCells` directly.
result = ""
for cell in parseTableCells(s, delim):
result.add cell.text
for i in cell.text.len..<cell.width:

View File

@@ -26,7 +26,7 @@ proc handleHexChar*(c: char): int {.inline.} =
of '0'..'9': result = (ord(c) - ord('0'))
of 'a'..'f': result = (ord(c) - ord('a') + 10)
of 'A'..'F': result = (ord(c) - ord('A') + 10)
else: discard
else: result = 0
proc decodePercent*(s: openArray[char], i: var int): char =
## Converts `%xx` hexadecimal to the character with ordinal number `xx`.

View File

@@ -75,11 +75,11 @@ const
const
signMask*: BitsType = not (not BitsType(0) shr 1)
proc constructDouble*(bits: BitsType): Double =
result.bits = bits
proc constructDouble*(bits: BitsType): Double =
result = Double(bits: bits)
proc constructDouble*(value: ValueType): Double =
result.bits = cast[typeof(result.bits)](value)
proc constructDouble*(value: ValueType): Double =
result = Double(bits: cast[typeof(result.bits)](value))
proc physicalSignificand*(this: Double): BitsType {.noSideEffect.} =
return this.bits and significandMask
@@ -1234,7 +1234,7 @@ proc formatDigits*[T: Ordinal](buffer: var openArray[char]; pos: T; digits: uint
when true: #defined(vcc) and not defined(clang):
## VC does not inline the memmove call below. (Even if compiled with /arch:AVX2.)
## However, memcpy will be inlined.
var tmp: array[16, char]
var tmp = default(array[16, char])
for i in 0..<16: tmp[i] = buffer[i+pos+decimalPoint]
for i in 0..<16: buffer[i+pos+decimalPoint+1] = tmp[i]
else:

View File

@@ -41,6 +41,7 @@ proc diffFiles*(path1, path2: string): tuple[output: string, same: bool] =
# This could be customized, e.g. non-git diff with `diff -uNdr`, or with
# git diff options (e.g. --color-moved, --word-diff).
# in general, `git diff` has more options than `diff`.
result = default(tuple[output: string, same: bool])
var status = 0
(result.output, status) = execCmdEx("git diff --no-index $1 $2" % [path1.quoteShell, path2.quoteShell])
doAssert (status == 0) or (status == 1)

View File

@@ -36,7 +36,7 @@ iterator walkDirRecFilter*(dir: string, follow: proc(entry: PathEntry): bool = n
]#
var stack = @["."]
var checkDir = checkDir
var entry: PathEntry
var entry: PathEntry = PathEntry()
while stack.len > 0:
let d = stack.pop()
for k, p in walkDir(dir / d, relative = true, checkDir = checkDir):

View File

@@ -158,6 +158,7 @@ proc getTempDir*(): string {.rtl, extern: "nos$1",
const tempDir {.strdefine.}: string = tempDirDefault
result = tempDir
else:
result = ""
when nimvm:
getTempDirImpl(result)
else:

View File

@@ -997,6 +997,7 @@ proc sameFile*(path1, path2: string): bool {.rtl, extern: "nos$1",
##
## See also:
## * `sameFileContent proc`_
result = false
when defined(windows):
var success = true
var f1 = openHandle(path1)

View File

@@ -39,11 +39,11 @@ const
exponentMask: BitsType = maxIeeeExponent shl (significandSize - 1)
signMask: BitsType = not (not BitsType(0) shr 1)
proc constructSingle(bits: BitsType): Single =
result.bits = bits
proc constructSingle(bits: BitsType): Single =
result = Single(bits: bits)
proc constructSingle(value: ValueType): Single =
result.bits = cast[typeof(result.bits)](value)
proc constructSingle(value: ValueType): Single =
result = Single(bits: cast[typeof(result.bits)](value))
proc physicalSignificand(this: Single): BitsType {.noSideEffect.} =
return this.bits and significandMask

View File

@@ -399,6 +399,8 @@ proc readLine*(f: File, line: var string): bool {.tags: [ReadIOEffect],
## character(s) are not part of the returned string. Returns `false`
## if the end of the file has been reached, `true` otherwise. If
## `false` is returned `line` contains no new data.
result = false
proc c_memchr(s: pointer, c: cint, n: csize_t): pointer {.
importc: "memchr", header: "<string.h>".}
@@ -737,6 +739,8 @@ proc open*(f: var File, filename: string,
discard c_setvbuf(f, nil, IOFBF, cast[csize_t](bufSize))
elif bufSize == 0:
discard c_setvbuf(f, nil, IONBF, 0)
else:
result = false
proc reopen*(f: File, filename: string, mode: FileMode = fmRead): bool {.
tags: [], benign.} =
@@ -754,6 +758,8 @@ proc reopen*(f: File, filename: string, mode: FileMode = fmRead): bool {.
closeIgnoreError(f)
return false
result = true
else:
result = false
proc open*(f: var File, filehandle: FileHandle,
mode: FileMode = fmRead): bool {.tags: [], raises: [], benign.} =
@@ -778,6 +784,7 @@ proc open*(filename: string,
## could not be opened.
##
## The file handle associated with the resulting `File` is not inheritable.
result = default(File)
if not open(result, filename, mode, bufSize):
raise newException(IOError, "cannot open: " & filename)

View File

@@ -152,10 +152,12 @@ when not (defined(cpu16) or defined(cpu8)):
yield result
proc newWideCString*(size: int): WideCStringObj =
result = default(WideCStringObj)
createWide(result, size * 2 + 2)
proc newWideCString*(source: cstring, L: int): WideCStringObj =
## Warning:: `source` needs to be preallocated with the length `L`
result = default(WideCStringObj)
createWide(result, L * 2 + 2)
var d = 0
for ch in runes(source, L):