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

strftime() zero size check #2238

Closed
yumeyao opened this issue Apr 16, 2021 · 1 comment
Closed

strftime() zero size check #2238

yumeyao opened this issue Apr 16, 2021 · 1 comment

Comments

@yumeyao
Copy link
Contributor

yumeyao commented Apr 16, 2021

When I was browsing the code I came across the following comment about #367:

      if (size >= tm_format.size() * 256) {
        // If the buffer is 256 times larger than the format string, assume
        // that `strftime` gives an empty result. There doesn't seem to be a
        // better way to distinguish the two cases:
        // https://github.com/fmtlib/fmt/issues/367
        break;
      }

a possibly simple way to fix this is adding an extra space in parse():

    tm_format.reserve(detail::to_unsigned(end - it + 1));
    tm_format.append(it, end);;
 +  tm_format.push_back(' ');
    tm_format.push_back('\0');
    return end;

and remove the space after formatting in format():

 -  return std::copy(buf.begin(), buf.end(), ctx.out());
 +  return std::copy(buf.begin(), buf.end() - 1, ctx.out());
@vitaut
Copy link
Contributor

vitaut commented Apr 16, 2021

Good idea, thanks. Could you submit a PR?

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