Skip to content

Small inherited defects: self-overlapping strncpy, map.txt leak, warnings #7

Description

@lepht

Three minor issues inherited from upstream. None urgent; grouped so they don't get lost.

Self-overlapping strncpyworkspace/all/common/config.c:556

CFG_setFontStyle() calls CFG_setFontFile(CFG_getFontFile()), and CFG_getFontFile() returns settings.fontFile — so CFG_setFontFile ends up doing:

strncpy(settings.fontFile, settings.fontFile, sizeof(settings.fontFile) - 1);

Source and destination are the same buffer. Undefined behaviour per the standard; harmless with glibc's forward copy, which is why it has never bitten.

Caught by AddressSanitizer (strncpy-param-overlap), where it aborts on startup and blocks ASan runs of the whole app — that's the real cost. I had to build with ASAN_OPTIONS=replace_str=0 to get past it while testing #1 and #2, which disables string-function checking everywhere else too.

Fix: guard the self-assignment, or have CFG_setFontStyle reload the font without routing through the setter.

map.txt double-strdup leak — Directory_index() and getRoms() in nextui.c

Hash_set() already does strdup(value) internally, but both call sites pass strdup(value) into it:

Hash_set(map, key, strdup(value));   // inner copy leaks

The outer copy is never freed. Leaks once per aliased entry on every directory load that has a map.txt. Small and bounded, but it's on a path that runs constantly while browsing.

Fix: pass value directly. The search indexer added in #2 already does it the correct way, so that call site needs no change.

Warnings

-Wall on nextui.c is not clean: several unused variables, and a -Wparentheses hit in the quick menu background path where && and || are mixed without parentheses. That one parses as intended but reads ambiguously, and it's the kind of expression that gets "fixed" wrongly later.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions