diff --git a/winsup/cygwin/glob.cc b/winsup/cygwin/glob.cc index 0b85a147a..dadc67e4c 100644 --- a/winsup/cygwin/glob.cc +++ b/winsup/cygwin/glob.cc @@ -203,13 +203,10 @@ check_classes_expr(const Char *&cptr, wint_t *classbuf = NULL, if (classbuf) { const Char *class_p = ctype + 1; size_t clen = cptr - class_p; - size_t idx; - if (clen < classbufsize) { - for (idx = 0; idx < clen; ++idx) - classbuf[idx] = CHAR(class_p[idx]); - classbuf[idx] = '\0'; - } else + if (clen < classbufsize) + *wcipncpy (classbuf, class_p, clen) = '\0'; + else ctype = NULL; } cptr++; /* Advance cptr to closing RBRACKET of class expr */ diff --git a/winsup/cygwin/local_includes/wchar.h b/winsup/cygwin/local_includes/wchar.h index b09d014c0..125e49ece 100644 --- a/winsup/cygwin/local_includes/wchar.h +++ b/winsup/cygwin/local_includes/wchar.h @@ -101,6 +101,36 @@ wcincmp (const wint_t *s1, const wint_t *s2, size_t n) return (0); } +/* like wcpcpy, just for wint_t */ +static inline wint_t * +wcipcpy (wint_t *s1, const wint_t *s2) +{ + while ((*s1++ = *s2++)) + ; + return --s1; +} + +/* like wcpncpy, just for wint_t */ +static inline wint_t * +wcipncpy (wint_t *dst, const wint_t *src, size_t count) +{ + wint_t *ret = NULL; + + while (count > 0) + { + --count; + if ((*dst++ = *src++) == L'\0') + { + ret = dst - 1; + break; + } + } + while (count-- > 0) + *dst++ = L'\0'; + + return ret ? ret : dst; +} + #ifdef __cplusplus } #endif