~vcs-imports/eglibc/trunk

« back to all changes in this revision

Viewing changes to libc/debug/strncpy_chk.c

  • Committer: joseph
  • Date: 2014-01-03 17:51:28 UTC
  • Revision ID: svn-v4:7b3dc134-2b1b-0410-93df-9e9f96275f8d:trunk:24942
Merge changes between r24468 and r24941 from /fsf/trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 1991-2013 Free Software Foundation, Inc.
 
1
/* Copyright (C) 1991-2014 Free Software Foundation, Inc.
2
2
   This file is part of the GNU C Library.
3
3
 
4
4
   The GNU C Library is free software; you can redistribute it and/or
26
26
     size_t n;
27
27
     size_t s1len;
28
28
{
29
 
  char c;
30
 
  char *s = s1;
31
 
 
32
29
  if (__builtin_expect (s1len < n, 0))
33
30
    __chk_fail ();
34
31
 
35
 
  --s1;
36
 
 
37
 
  if (n >= 4)
38
 
    {
39
 
      size_t n4 = n >> 2;
40
 
 
41
 
      for (;;)
42
 
        {
43
 
          c = *s2++;
44
 
          *++s1 = c;
45
 
          if (c == '\0')
46
 
            break;
47
 
          c = *s2++;
48
 
          *++s1 = c;
49
 
          if (c == '\0')
50
 
            break;
51
 
          c = *s2++;
52
 
          *++s1 = c;
53
 
          if (c == '\0')
54
 
            break;
55
 
          c = *s2++;
56
 
          *++s1 = c;
57
 
          if (c == '\0')
58
 
            break;
59
 
          if (--n4 == 0)
60
 
            goto last_chars;
61
 
        }
62
 
      n = n - (s1 - s) - 1;
63
 
      if (n == 0)
64
 
        return s;
65
 
      goto zero_fill;
66
 
    }
67
 
 
68
 
 last_chars:
69
 
  n &= 3;
70
 
  if (n == 0)
71
 
    return s;
72
 
 
73
 
  do
74
 
    {
75
 
      c = *s2++;
76
 
      *++s1 = c;
77
 
      if (--n == 0)
78
 
        return s;
79
 
    }
80
 
  while (c != '\0');
81
 
 
82
 
 zero_fill:
83
 
  do
84
 
    *++s1 = '\0';
85
 
  while (--n > 0);
86
 
 
87
 
  return s;
 
32
  return strncpy (s1, s2, n);
88
33
}