Skip to content

StringUtilities::ToInt/ToDouble silently return 0 on parse failure #19

@jkalias

Description

@jkalias

Problem

StringUtilities::ToInt and ToDouble (src/string_utilities.cc) wrap std::stoll / std::stod in a catch (...) that returns 0 / 0.0:

int64_t StringUtilities::ToInt(const std::wstring& s) {
    try { return std::stoll(s); } catch (...) { return 0; }
}

Impact

Any malformed or out-of-range numeric string is silently converted to 0 with no error. std::stoll/std::stod throw std::out_of_range for values that don't fit, so e.g. a legitimately huge integer becomes 0 rather than failing. This is silent data corruption on the fetch path, and it masks the integer-truncation issue as well.

Suggested direction

Surface the failure instead of swallowing it — throw, or return a status/std::optional the caller must handle. At minimum, distinguish "parsed 0" from "failed to parse".

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions