/dev/clipboard corrupted
Corinna Vinschen
corinna-cygwin@cygwin.com
Wed Jul 4 08:27:00 GMT 2012
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
More information about the Cygwin-developers
mailing list