comparison src/misc2.c @ 2768:c5e47b752f07 v7.3.160

updated for version 7.3.160 Problem: Unsafe string copying. Solution: Use vim_strncpy() instead of strcpy(). Use vim_strcat() instead of strcat().
author Bram Moolenaar <bram@vim.org>
date Mon, 11 Apr 2011 16:56:35 +0200
parents 4549e0e7fbb6
children 0bef86c5c985
comparison
equal deleted inserted replaced
2767:9d6d058f0ebb 2768:c5e47b752f07
1642 char_u *from; 1642 char_u *from;
1643 size_t len; 1643 size_t len;
1644 { 1644 {
1645 STRNCPY(to, from, len); 1645 STRNCPY(to, from, len);
1646 to[len] = NUL; 1646 to[len] = NUL;
1647 }
1648
1649 /*
1650 * Like strcat(), but make sure the result fits in "tosize" bytes and is
1651 * always NUL terminated.
1652 */
1653 void
1654 vim_strcat(to, from, tosize)
1655 char_u *to;
1656 char_u *from;
1657 size_t tosize;
1658 {
1659 size_t tolen = STRLEN(to);
1660 size_t fromlen = STRLEN(from);
1661
1662 if (tolen + fromlen + 1 > tosize)
1663 {
1664 mch_memmove(to + tolen, from, tosize - tolen - 1);
1665 to[tosize - 1] = NUL;
1666 }
1667 else
1668 STRCPY(to + tolen, from);
1647 } 1669 }
1648 1670
1649 /* 1671 /*
1650 * Isolate one part of a string option where parts are separated with 1672 * Isolate one part of a string option where parts are separated with
1651 * "sep_chars". 1673 * "sep_chars".