Author: rfm
Date: Sat Jun 25 20:27:33 2016
New Revision: 39920

URL: http://svn.gna.org/viewcvs/gnustep?rev=39920&view=rev
Log:
Fixup error in return value when buffer too small

Modified:
    libs/base/trunk/Source/GSString.m

Modified: libs/base/trunk/Source/GSString.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Source/GSString.m?rev=39920&r1=39919&r2=39920&view=diff
==============================================================================
--- libs/base/trunk/Source/GSString.m   (original)
+++ libs/base/trunk/Source/GSString.m   Sat Jun 25 20:27:33 2016
@@ -896,6 +896,7 @@
       if (maxLength > 1)
        {
           unichar       *buf = (unichar*)(void*)buffer;
+         BOOL          result = (length < maxLength) ? YES : NO;
 
           if (maxLength <= length)
             {
@@ -906,7 +907,7 @@
               buf[index] = (unichar)TINY_STRING_CHAR(s, index);
             }
           buf[index] = 0;
-          return YES;
+          return result;
        }
       return NO;
     }
@@ -914,6 +915,8 @@
     {
       if (maxLength > 0)
        {
+         BOOL  result = (length < maxLength) ? YES : NO;
+
           if (maxLength <= length)
             {
               length = maxLength - 1;
@@ -923,7 +926,7 @@
               buffer[index] = (char)TINY_STRING_CHAR(s, index);
             }
           buffer[index] = 0;
-          return YES;
+          return result;
         }
       return NO;
     }
@@ -5930,6 +5933,8 @@
     }
   if (NSUTF8StringEncoding == encoding)
     {
+      BOOL     result = (length < maxLength) ? YES : NO;
+
       /* We are already using UTF-8 so we can just copy directly.
        */
       if (maxLength <= length)
@@ -5947,10 +5952,12 @@
           index--;
         }
       buffer[index] = '\0';
-      return YES;
+      return result;
     }
   else if (isByteEncoding(encoding))
     {
+      BOOL     result = (length < maxLength) ? YES : NO;
+
       /* We want a single-byte encoding (ie ascii is a subset),
        * so as long as this constant string is ascii, we can just
        * copy directly.
@@ -5968,9 +5975,9 @@
             }
         }
       if (index == length)
-        {
+       {
           buffer[index] = '\0';
-          return YES;                   // All copied.
+          return result;
         }
       // Fall through to use superclass method.
     }


_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to