Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fmt::vformat() throws an exception on Android x86 during chrono formatting. #4244

Open
TheStormN opened this issue Nov 25, 2024 · 0 comments

Comments

@TheStormN
Copy link

Hello,

I believe I've discovered a bug in latest version of fmt when compiled using Clang in 32bit x86 mode. We have a legacy codebase with some Time functions wrappers which we try to refactor by using more modern tooling. We use fmt as polyfill for platforms which still don't have proper std:;format() support.

The current issue is reproducible only on our Android x86 pipeline, on all other mobile and desktop platforms the code works as expected. The exception being thrown is fmt::v11::format_error. I've managed to strip down the code to a small reproducible example. Here's the CompilerExplorer link: https://godbolt.org/z/v1Mezdd8T

The moment you remove the -m32 flag the program executes successfully.

#include <chrono>
#include <iostream>

#include <cassert>

#include <fmt/format.h>
#include <fmt/chrono.h>

template <class Clock, class Duration = typename Clock::duration>
std::string formatTime(const std::string& format, const std::chrono::time_point<Clock, Duration>& time)
{
    return fmt::vformat("{:" + format + '}', fmt::make_format_args(time));
}

std::string fromUnixEpochToRFC1123(const int64_t epoch)
{
    std::chrono::system_clock::time_point timePoint{ std::chrono::seconds(epoch / 1000) };

    return formatTime("%a, %d %b %Y %H:%M:%S GMT", std::chrono::floor<std::chrono::seconds>(timePoint));
}

int main() {
    auto result = fromUnixEpochToRFC1123(32536850400000);
    bool isResultExpected = result == "Mon, 19 Jan 3001 22:00:00 GMT";
    assert(isResultExpected);
    std::cout << result << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant