Zero-sized destination buffers when converting to UTF-8 shouldn't overflow.
authorRyan C. Gordon <icculus@icculus.org>
Fri, 20 Aug 2010 02:35:01 -0400
changeset 1092 12c87d886a75
parent 1091 0a103bf74f1c
child 1093 738b2ee912b9
Zero-sized destination buffers when converting to UTF-8 shouldn't overflow.
src/physfs.h
src/physfs_unicode.c
--- a/src/physfs.h	Fri Aug 20 01:25:32 2010 -0400
+++ b/src/physfs.h	Fri Aug 20 02:35:01 2010 -0400
@@ -2320,7 +2320,7 @@
  *
  * Strings that don't fit in the destination buffer will be truncated, but
  *  will always be null-terminated and never have an incomplete UTF-8
- *  sequence at the end.
+ *  sequence at the end. If the buffer length is 0, this function does nothing.
  *
  *   \param src Null-terminated source string in UCS-4 format.
  *   \param dst Buffer to store converted UTF-8 string.
@@ -2342,7 +2342,7 @@
  *
  * Strings that don't fit in the destination buffer will be truncated, but
  *  will always be null-terminated and never have an incomplete UCS-4
- *  sequence at the end.
+ *  sequence at the end. If the buffer length is 0, this function does nothing.
  *
  *   \param src Null-terminated source string in UTF-8 format.
  *   \param dst Buffer to store converted UCS-4 string.
@@ -2365,7 +2365,7 @@
  *
  * Strings that don't fit in the destination buffer will be truncated, but
  *  will always be null-terminated and never have an incomplete UTF-8
- *  sequence at the end.
+ *  sequence at the end. If the buffer length is 0, this function does nothing.
  *
  * Please note that UCS-2 is not UTF-16; we do not support the "surrogate"
  *  values at this time.
@@ -2391,7 +2391,7 @@
  *
  * Strings that don't fit in the destination buffer will be truncated, but
  *  will always be null-terminated and never have an incomplete UCS-2
- *  sequence at the end.
+ *  sequence at the end. If the buffer length is 0, this function does nothing.
  *
  * Please note that UCS-2 is not UTF-16; we do not support the "surrogate"
  *  values at this time.
@@ -2417,7 +2417,7 @@
  *
  * Strings that don't fit in the destination buffer will be truncated, but
  *  will always be null-terminated and never have an incomplete UTF-8
- *  sequence at the end.
+ *  sequence at the end. If the buffer length is 0, this function does nothing.
  *
  * Please note that we do not supply a UTF-8 to Latin1 converter, since Latin1
  *  can't express most Unicode codepoints. It's a legacy encoding; you should
--- a/src/physfs_unicode.c	Fri Aug 20 01:25:32 2010 -0400
+++ b/src/physfs_unicode.c	Fri Aug 20 02:35:01 2010 -0400
@@ -305,6 +305,7 @@
 } /* utf8fromcodepoint */
 
 #define UTF8FROMTYPE(typ, src, dst, len) \
+    if (len == 0) return; \
     len--;  \
     while (len) \
     { \