This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/71501] New: printf %s error on str[5], for example: strncpy(str, "12345", 5)
- From: "daemon.sniper at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 11 Jun 2016 14:09:52 +0000
- Subject: [Bug c/71501] New: printf %s error on str[5], for example: strncpy(str, "12345", 5)
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71501
Bug ID: 71501
Summary: printf %s error on str[5], for example: strncpy(str,
"12345", 5)
Product: gcc
Version: 4.8.5
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: daemon.sniper at gmail dot com
Target Milestone: ---
code:
===============================
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char *n = "12345";
char c[5] = {0};
strncpy(c, "12345", 5);
printf("%s----%c,%c,%c,%c,%c----->\n", c, c[0], c[1], c[2], c[3], c[4]);
return 0;
}
==============================
output:
=========================
1234----1,2,3,4,5----->
=========================
it looks like only happend on version "gcc version 4.8.5 20150623 (Red Hat
4.8.5-4) (GCC) "