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

Windows strftime issue #965

Closed
shirolimit opened this issue Dec 6, 2018 · 1 comment
Closed

Windows strftime issue #965

shirolimit opened this issue Dec 6, 2018 · 1 comment

Comments

@shirolimit
Copy link

There is a problem with time formatting on Windows. Sometimes it can throw SEH exception.

The problem is in CRT strftime implementation, which fmtlib uses for time formatting.
Code from https://github.com/fmtlib/fmt/blob/master/include/fmt/time.h#L358

std::size_t size = buf.capacity() - start;
std::size_t count =
internal::strftime(&buf[start], size, &tm_format[0], &tm);

If the size of the buffer equals it's capacity, so that the value of size variable results in 0, then CRT throws SEH exception.

The reason is that MS implementation checks validity of the second parameter of strftime function (it is not standard compliant, btw, so maybe they'll fix).

Code snippet from MS strftime implementation:

extern "C" size_t __cdecl _Strftime_l (
    _Out_writes_z_(maxsize) char * const string,
    _In_ size_t                    const maxsize,
    _In_z_ const char *            const format,
    _In_ const tm *                const timeptr,
    _In_ void *                    const lc_time_arg,
    _In_opt_ _locale_t             const locale
    )
{
    _LocaleUpdate locale_update(locale);
    unsigned int const lc_time_cp = locale_update.GetLocaleT()->locinfo->lc_time_cp;

    _VALIDATE_RETURN(string != nullptr, EINVAL, 0)
    _VALIDATE_RETURN(maxsize != 0,      EINVAL, 0)

Possible fixes:

  1. check for zero buffer size prior to strftime call
  2. set invalid parameter handler via _set_invalid_parameter_handler, to avoid SEH exceptions (bad idea, cause it also need to store previous one, and could be replaced)
@vitaut
Copy link
Contributor

vitaut commented Dec 7, 2018

Implemented a workaround in acfa95d, thanks for reporting.

@vitaut vitaut closed this as completed Dec 7, 2018
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

2 participants