- added = strlcpy(fnametmp + length, f, maxname);
- if (added >= maxname)
- added = maxname - 1;
- suf = fnametmp + length + added;
-
- /* Trim any dangling high-bit chars if the first-trimmed char (if any) is
- * also a high-bit char, just in case we cut into a multi-byte sequence.
- * We are guaranteed to stop because of the leading '.' we added. */
- if ((int)f[added] & 0x80) {
- while ((int)suf[-1] & 0x80)
+ if (maxname) {
+ int added = strlcpy(fnametmp + length, f, maxname);
+ if (added >= maxname)
+ added = maxname - 1;
+ suf = fnametmp + length + added;
+
+ /* Trim any dangling high-bit chars if the first-trimmed char (if any) is
+ * also a high-bit char, just in case we cut into a multi-byte sequence.
+ * We are guaranteed to stop because of the leading '.' we added. */
+ if ((int)f[added] & 0x80) {
+ while ((int)suf[-1] & 0x80)
+ suf--;
+ }
+ /* trim one trailing dot before our suffix's dot */
+ if (suf[-1] == '.')