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

sprintf_s doesn't handle empty string correctly #97

Closed
cliffwy opened this issue May 10, 2021 · 2 comments
Closed

sprintf_s doesn't handle empty string correctly #97

cliffwy opened this issue May 10, 2021 · 2 comments
Assignees
Labels
Milestone

Comments

@cliffwy
Copy link

cliffwy commented May 10, 2021

call this function: sprintf_s(buff, sizeof(buff), "%s", "");
it gives error. because the call to "vsnprintf" returns 0. which is correct because it's printing empty string.

if (unlikely(ret <= 0)) {
        char errstr[128] = "sprintf_s: ";
        strcat(errstr, strerror(errno));
        handle_error(dest, dmax, errstr, -ret);
    }
@rurban rurban self-assigned this May 10, 2021
@rurban rurban added the bug label Oct 30, 2021
@rurban rurban added this to the 3.7 milestone Oct 30, 2021
rurban added a commit that referenced this issue Oct 30, 2021
all other printf's use < correctly
Fixes GH #97
rurban added a commit that referenced this issue Oct 31, 2021
all other printf's use < correctly
Fixes GH #97
@DBJDBJ
Copy link

DBJDBJ commented Nov 8, 2021

The whole of ISO C does not handle the empty string. Correctly or not.

strlen("") == 0

""[0] == '\0' 

But then a lot of people have the same problem, thus stepping on others' toes. An example, from a different galaxy, but on the same subject.

Live with it™

😉

@rurban
Copy link
Owner

rurban commented Nov 8, 2021

The _s extension defines what to do with an empty string and NULL, which I'm going to implement properly in the printf branch.
There were too many edge-cases not handled correctly.

@rurban rurban closed this as completed Jan 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants