[Issue 22266] New: core.stdc.stdio.snprintf returns wrong value if the buffer is not sufficiently large

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Sep 2 12:09:26 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=22266

          Issue ID: 22266
           Summary: core.stdc.stdio.snprintf returns wrong value if the
                    buffer is not sufficiently large
           Product: D
           Version: D2
          Hardware: All
                OS: Windows
            Status: NEW
          Severity: major
          Priority: P1
         Component: tools
          Assignee: nobody at puremagic.com
          Reporter: ogion.art at gmail.com

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.

--


More information about the Digitalmars-d-bugs mailing list