Fix a mishandled error condition when reading from a cut buffer.
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sat, 7 Aug 2010 17:30:48 +0000 (17:30 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sat, 7 Aug 2010 17:30:48 +0000 (17:30 +0000)
This also adds a change of behaviour (resetting nread) in the case
of multi-chunk selection receipt, but I haven't found a way to test
the latter.

git-svn-id: svn://svn.tartarus.org/sgt/utils@8977 cda61777-01e9-0310-a592-d414129be87e

xcopy/xcopy.c

index 5a654a0..318fc32 100644 (file)
@@ -36,7 +36,7 @@ int fork_when_writing = True;
 /* selection data */
 char *seltext;
 int sellen, selsize;
-#define SELDELTA 16384
+#define SELDELTA 64
 
 /* functional parameters */
 int reading;                           /* read instead of writing? */
@@ -616,5 +616,20 @@ void do_paste(Window window, Atom property, int Delete) {
         XFree(data);
         if (nitems == 0)
             break;
+       if (bytes_after == 0) {
+           /*
+            * We've come to the end of the property we're reading.
+            * If we have the Delete flag set, we may be receiving
+            * the selection data in multiple chunks, in which case
+            * we should reset nread to zero so that when the next
+            * chunk arrives we resume reading from the start of the
+            * replaced property. Otherwise, this is our cue to
+            * exit.
+            */
+           if (Delete)
+               nread = 0;
+           else
+               break;
+       }
     }
 }