diff --git a/lib/std/private/asciitables.nim b/lib/std/private/asciitables.nim index cbc595651c..89dc94b0d4 100644 --- a/lib/std/private/asciitables.nim +++ b/lib/std/private/asciitables.nim @@ -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.. 0: let d = stack.pop() for k, p in walkDir(dir / d, relative = true, checkDir = checkDir): diff --git a/lib/std/private/osappdirs.nim b/lib/std/private/osappdirs.nim index 07a6809bb3..d0c2f7afcc 100644 --- a/lib/std/private/osappdirs.nim +++ b/lib/std/private/osappdirs.nim @@ -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: diff --git a/lib/std/private/ospaths2.nim b/lib/std/private/ospaths2.nim index bc69ff7256..b43576424d 100644 --- a/lib/std/private/ospaths2.nim +++ b/lib/std/private/ospaths2.nim @@ -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) diff --git a/lib/std/private/schubfach.nim b/lib/std/private/schubfach.nim index b8c85d2bc7..21be448304 100644 --- a/lib/std/private/schubfach.nim +++ b/lib/std/private/schubfach.nim @@ -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 diff --git a/lib/std/syncio.nim b/lib/std/syncio.nim index aeb6055de3..5c97712a43 100644 --- a/lib/std/syncio.nim +++ b/lib/std/syncio.nim @@ -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: "".} @@ -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) diff --git a/lib/std/widestrs.nim b/lib/std/widestrs.nim index 2ddf80d14e..ad91f97016 100644 --- a/lib/std/widestrs.nim +++ b/lib/std/widestrs.nim @@ -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): diff --git a/lib/system/alloc.nim b/lib/system/alloc.nim index 3de6d87137..e2dd430759 100644 --- a/lib/system/alloc.nim +++ b/lib/system/alloc.nim @@ -575,6 +575,7 @@ proc isAccessible(a: MemRegion, p: pointer): bool {.inline.} = result = contains(a.chunkStarts, pageIndex(p)) proc contains[T](list, x: T): bool = + result = false var it = list while it != nil: if it == x: return true @@ -1164,6 +1165,7 @@ proc dealloc(allocator: var MemRegion, p: pointer) = rawDealloc(allocator, p) proc realloc(allocator: var MemRegion, p: pointer, newsize: Natural): pointer = + result = nil if newsize > 0: result = alloc(allocator, newsize) if p != nil: diff --git a/lib/system/arc.nim b/lib/system/arc.nim index d001fcaa5e..7537fd2125 100644 --- a/lib/system/arc.nim +++ b/lib/system/arc.nim @@ -211,6 +211,7 @@ when defined(gcOrc): #include cyclecollector proc nimDecRefIsLast(p: pointer): bool {.compilerRtl, inl.} = + result = false if p != nil: var cell = head(p) diff --git a/lib/system/deepcopy.nim b/lib/system/deepcopy.nim index 72d35f5186..0f7d0eaae2 100644 --- a/lib/system/deepcopy.nim +++ b/lib/system/deepcopy.nim @@ -41,6 +41,7 @@ proc initPtrTable(): PtrTable = template deinit(t: PtrTable) = dealloc(t) proc get(t: PtrTable; key: pointer): pointer = + result = nil var h = hashPtr(key) while true: let k = t.data[h and t.max][0] diff --git a/lib/system/dollars.nim b/lib/system/dollars.nim index 89a739d5a7..c26dad5b76 100644 --- a/lib/system/dollars.nim +++ b/lib/system/dollars.nim @@ -11,24 +11,30 @@ when not defined(nimPreviewSlimSystem): func `$`*(x: float | float32): string = ## Outplace version of `addFloat`. + result = "" result.addFloat(x) proc `$`*(x: int): string {.raises: [].} = ## Outplace version of `addInt`. + result = "" result.addInt(x) proc `$`*(x: int64): string {.raises: [].} = ## Outplace version of `addInt`. + result = "" result.addInt(x) proc `$`*(x: uint64): string {.raises: [].} = ## Outplace version of `addInt`. + result = "" addInt(result, x) # same as old `ctfeWhitelist` behavior, whether or not this is a good idea. template gen(T) = # xxx simplify this by supporting this in compiler: int{lit} | uint64{lit} | int64{lit} - func `$`*(x: T{lit}): string {.compileTime.} = result.addInt(x) + func `$`*(x: T{lit}): string {.compileTime.} = + result = "" + result.addInt(x) gen(int) gen(uint64) gen(int64) diff --git a/lib/system/integerops.nim b/lib/system/integerops.nim index 4ef3594f11..22875b330d 100644 --- a/lib/system/integerops.nim +++ b/lib/system/integerops.nim @@ -117,6 +117,7 @@ template divImplFallback(name, T) {.dirty.} = if a == low(T) and b == T(-1): result = true else: + result = false res[] = a div b divImplFallback(nimDivInt, int) diff --git a/lib/system/memalloc.nim b/lib/system/memalloc.nim index a94d0995c8..7e1b5f4b65 100644 --- a/lib/system/memalloc.nim +++ b/lib/system/memalloc.nim @@ -85,7 +85,7 @@ when hasAlloc and not defined(js): else: template incStat(what: untyped) = discard - proc getAllocStats*(): AllocStats = discard + proc getAllocStats*(): AllocStats = result = default(AllocStats) template alloc*(size: Natural): pointer = ## Allocates a new memory block with at least `size` bytes. diff --git a/lib/system/orc.nim b/lib/system/orc.nim index 351dbf26d4..73b68bb9d2 100644 --- a/lib/system/orc.nim +++ b/lib/system/orc.nim @@ -509,6 +509,7 @@ proc rememberCycle(isDestroyAction: bool; s: Cell; desc: PNimTypeV2) {.noinline. registerCycle(s, desc) proc nimDecRefIsLastCyclicDyn(p: pointer): bool {.compilerRtl, inl.} = + result = false if p != nil: var cell = head(p) if (cell.rc and not rcMask) == 0: @@ -520,6 +521,7 @@ proc nimDecRefIsLastCyclicDyn(p: pointer): bool {.compilerRtl, inl.} = rememberCycle(result, cell, cast[ptr PNimTypeV2](p)[]) proc nimDecRefIsLastDyn(p: pointer): bool {.compilerRtl, inl.} = + result = false if p != nil: var cell = head(p) if (cell.rc and not rcMask) == 0: @@ -533,6 +535,7 @@ proc nimDecRefIsLastDyn(p: pointer): bool {.compilerRtl, inl.} = unregisterCycle(cell) proc nimDecRefIsLastCyclicStatic(p: pointer; desc: PNimTypeV2): bool {.compilerRtl, inl.} = + result = false if p != nil: var cell = head(p) if (cell.rc and not rcMask) == 0: diff --git a/lib/system/strmantle.nim b/lib/system/strmantle.nim index c3e48c14c5..694ef64257 100644 --- a/lib/system/strmantle.nim +++ b/lib/system/strmantle.nim @@ -32,6 +32,7 @@ proc ltStrings(a, b: string): bool {.inline, compilerproc.} = cmpStrings(a, b) < 0 proc eqStrings(a, b: string): bool {.inline, compilerproc.} = + result = false let alen = a.len let blen = b.len if alen == blen: diff --git a/lib/system/threadlocalstorage.nim b/lib/system/threadlocalstorage.nim index e6ad9dca58..625e602bf5 100644 --- a/lib/system/threadlocalstorage.nim +++ b/lib/system/threadlocalstorage.nim @@ -88,6 +88,7 @@ else: importc: "pthread_setspecific", header: pthreadh.} proc threadVarAlloc(): ThreadVarSlot {.inline.} = + result = default(ThreadVarSlot) discard pthread_key_create(addr(result), nil) proc threadVarSetValue(s: ThreadVarSlot, value: pointer) {.inline.} = discard pthread_setspecific(s, value)