This is the mail archive of the
cygwin-developers
mailing list for the Cygwin project.
Re: /dev/clipboard corrupted
- From: Corinna Vinschen <corinna-cygwin at cygwin dot com>
- To: cygwin-developers at cygwin dot com
- Date: Wed, 4 Jul 2012 10:27:07 +0200
- Subject: Re: /dev/clipboard corrupted
- References: <901292590.804659.1341325635435.JavaMail.open-xchange@email.1und1.de> <4FF31DDF.90103@towo.net> <20120704081503.GA19551@calimero.vinschen.de>
- Reply-to: cygwin-developers at cygwin dot com
On Jul 4 10:15, Corinna Vinschen wrote:
> On Jul 3 18:29, Thomas Wolff wrote:
> > filebuf [filebuflen] = 77;
> > fprintf (stderr, "filebuflen %d (overflow byte %d)\n", filebuflen, filebuf [filebuflen]);
> >
> > int n;
> > do {
> > n = read (fd, filebuf, filebuflen);
> > if (out_tty) {
> > filebuf [n] = 0;
>
> Hmm, what if n == filebuf?
Grr. Make that "n == filebuflen".
Try this testcase instead:
==== SNIP ====
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int
main (int argc, char * * argv)
{
char * fn = "/dev/clipboard";
int fd = open (fn, O_RDONLY | O_BINARY, 0);
if (fd < 0) {
exit (fd);
}
int out_tty = isatty (1);
int filebuflen = 100;
argc --;
if (argc > 0) {
int ret = sscanf (argv [1], "%d", & filebuflen);
}
fprintf (stderr, "filebuflen %d\n", filebuflen);
char * filebuf = malloc (filebuflen + 1);
int n;
do {
memset (filebuf, '\x01', filebuflen + 1);
n = read (fd, filebuf, filebuflen);
if (filebuf[n] != '\x01')
printf ("OVERWRITTEN\n");
if (out_tty) {
filebuf [n] = 0;
printf ("read %d bytes: <%s>\n", n, filebuf);
} else {
fprintf (stderr, "read %d bytes\n", n);
write (1, filebuf, n);
}
} while (n > 0);
close (fd);
}
==== SNAP ====
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Project Co-Leader cygwin AT cygwin DOT com
Red Hat