This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/79082] -Wformat-truncation inconsistent behaviour


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79082

Sylvestre Ledru <sylvestre at debian dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sylvestre at debian dot org

--- Comment #11 from Sylvestre Ledru <sylvestre at debian dot org> ---
Other testcase:
---
#include <stdio.h>
#include <stdint.h>
int main() {
    char* buf = new char[10];
    uint8_t data = 255;
    printf("%.2x\n", data);    // just print data
    snprintf(&buf[0], 2, "%.2x", data);
    return 0;
}
---

foo.c:7:13: note: format output 3 bytes into a destination of size 2
     snprintf(&buf[0], 2, "%.2x", data);
     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
---

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]