repo: rxvt-unicode-sixel
action: commit
revision: 
path_from: 
revision_from: 428dac2b4fd32ebd73ccdce88bfd2930d01bdb57:
path_to: 
revision_to: 
git.thebackupbox.net
rxvt-unicode-sixel
git clone git://git.thebackupbox.net/rxvt-unicode-sixel
commit 428dac2b4fd32ebd73ccdce88bfd2930d01bdb57
Author: Marc Lehmann 
Date:   Mon Dec 13 06:44:18 2004 +0000

    *** empty log message ***

diff --git a/src/misc.C b/src/misc.C
index a56e4de071d7f50ea02b04ca72ddbd6119b30c8d..
index ..e93dba7dff5ecb5455815dab373fe028ed348f68 100644
--- a/src/misc.C
+++ b/src/misc.C
@@ -108,17 +108,19 @@ rxvt_utf8towcs (const char *str, int len)

   unsigned char *s = (unsigned char *)str;

-  while (len--)
+  while (len)
     {
       if (s[0] < 0x80)
-        *p++ = *s++;
+        {
+          *p++ = *s++; len--;
+        }
       else if (len > 0 
                && s[0] >= 0xc2 && s[0] <= 0xdf 
                && (s[1] & 0xc0) == 0x80)
         {
           *p++ = ((s[0] & 0x1f) << 6)
                |  (s[1] & 0x3f);
-          s += 2;
+          s += 2; len -= 2;
         }
       else if (len > 1 
                && (   (s[0] == 0xe0                 && s[1] >= 0xa0 && s[1] <= 0xbf)
@@ -131,7 +133,7 @@ rxvt_utf8towcs (const char *str, int len)
           *p++ = ((s[0] & 0x0f) << 12)
                | ((s[1] & 0x3f) <<  6)
                |  (s[2] & 0x3f);
-          s += 3;
+          s += 3; len -= 3;
         }
       else if (len > 2
                && (   (s[0] == 0xf0                 && s[1] >= 0x90 && s[1] <= 0xbf)
@@ -145,12 +147,12 @@ rxvt_utf8towcs (const char *str, int len)
                | ((s[1] & 0x3f) << 12) 
                | ((s[2] & 0x3f) <<  6) 
                |  (s[3] & 0x3f);
-          s += 4;
+          s += 4; len -= 4;
         }
       else
         {
           *p++ = 0xfffd;
-          s++;
+          s++; len--;
         }
     }

diff --git a/src/screen.C b/src/screen.C
index e0d7dbca248ad99c01ec9371d08d49d50a4cd3eb..
index ..58368982ff30316647240f5c247c98445b331817 100644
--- a/src/screen.C
+++ b/src/screen.C
@@ -2716,7 +2716,7 @@ rxvt_term::selection_paste (Window win, Atom prop, bool delete_prop)
   XTextProperty ct;

   if (XGetWindowProperty (display->display, win, prop,
-                          0, (long)(PROP_SIZE / 4),
+                          0, PROP_SIZE / 4,
                           delete_prop, AnyPropertyType,
                           &ct.encoding, &ct.format,
                           &ct.nitems, &bytes_after,
@@ -2733,25 +2733,22 @@ rxvt_term::selection_paste (Window win, Atom prop, bool delete_prop)
     {
       // fetch and append remaining data
       XTextProperty ct2;
-      unsigned long bytes_after2;

       if (XGetWindowProperty (display->display, win, prop,
-                              ct.nitems / 4, (long) (bytes_after + 3) / 4,
+                              ct.nitems / 4, (bytes_after + 3) / 4,
                               delete_prop, AnyPropertyType,
                               &ct2.encoding, &ct2.format,
-                              &ct2.nitems, &bytes_after2,
+                              &ct2.nitems, &bytes_after,
                               &ct2.value) != Success)
         goto bailout;

       // realloc should be compatible to XFree, here, and elsewhere, too
-      ct.value = (unsigned char *)realloc (ct.value, ct.nitems + bytes_after);
-      memcpy (ct.value + ct.nitems, ct2.value, ct2.nitems);
+      ct.value = (unsigned char *)realloc (ct.value, ct.nitems + ct2.nitems + 1);
+      memcpy (ct.value + ct.nitems, ct2.value, ct2.nitems + 1);
       ct.nitems += ct2.nitems;

       XFree (ct2.value);
     }
-  else if (delete_prop)
-    XDeleteProperty (display->display, win, prop);

   if (ct.value == 0)
     goto bailout;

-----END OF PAGE-----