Bug 22266 – core.stdc.stdio.snprintf returns wrong value if the buffer is not sufficiently large
Status
NEW
Severity
major
Priority
P2
Component
tools
Product
D
Version
D2
Platform
All
OS
Windows
Creation time
2021-09-02T12:09:26Z
Last change time
2022-12-17T10:38:53Z
Assigned to
No Owner
Creator
Georgy Markov
Comments
Comment #0 by ogion.art — 2021-09-02T12:09:26Z
According to C99 specification, if the buffer is not sufficiently large, snprintf should still return the number of characters that would have been written. However, the implementation that DMD uses by default on Windows returns -1 instead.
void main() {
import core.stdc.stdio;
auto n = snprintf(null, 0, "test");
assert(n == 4); //fails
}
Passing either -m64 or -m32mscoff to DMD solves this.