From: <sil...@li...> - 2005-08-05 09:46:22
|
Update of /cvsroot/silgraphite/silgraphite/src/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18876/src/lib Modified Files: Platform.cpp Log Message: fix strlen bugs in grcompiler Index: Platform.cpp =================================================================== RCS file: /cvsroot/silgraphite/silgraphite/src/lib/Platform.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- Platform.cpp 16 Sep 2004 15:36:58 -0000 1.13 +++ Platform.cpp 5 Aug 2005 09:46:13 -0000 1.14 @@ -138,7 +138,7 @@ utf16 *utf16ncpy(utf16 *dest, const utf16 *src, size_t n) { - memcpy(dest, src, sizeof(utf16) * std::max(utf16len(src), n)); + memcpy(dest, src, sizeof(utf16) * std::min(utf16len(src, n), n)); return dest; } @@ -157,6 +157,14 @@ return s - start; } +size_t utf16len(const utf16 *s, size_t n) +{ + const utf16 *start = s; + for (; *s && s - start <= n; ++s) ; + + return s - start; +} + size_t utf8len(const char *s) { static const int is_initial[] = {1, 1, 0, 1}; |