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/71501] New: printf %s error on str[5], for example: strncpy(str, "12345", 5)


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) "

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