OSDN Git Service

Fix unnecessary call to __strncpy_chk2
authorNick Kralevich <nnk@google.com>
Fri, 27 Sep 2013 20:21:24 +0000 (13:21 -0700)
committerNick Kralevich <nnk@google.com>
Fri, 27 Sep 2013 20:21:24 +0000 (13:21 -0700)
commitd13c2b1ba6681fdbee73a044d988c3f9e1172d30
tree009f871a52478fef08570ac9365b5be3af08c397
parent8427b7450fe068db6484d161f7004661c4698858
Fix unnecessary call to __strncpy_chk2

If "n" is smaller than the size of "src", then we'll
never read off the end of src. It makes no sense to call
__strncpy_chk2 in those circumstances.

For example, consider the following code:

int main() {
  char src[10];
  char dst[5];
  memcpy(src, "0123456789", sizeof(src));
  strncpy(dst, src, sizeof(dst));
  dst[4] = '\0';
  printf("%s\n", dst);
  return 0;
}

In this code, it's clear that the strncpy will never read off
the end of src.

Change-Id: I9cf58857a0c5216b4576d21d3c1625e2913ccc03
libc/include/string.h