From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin-patches@cygwin.com
Subject: Re: [PATCH v2] Cygwin: clipboard: Fix a bug in read().
Date: Wed, 8 Dec 2021 11:19:05 +0100 [thread overview]
Message-ID: <YbCGmbAsZ4pJuttS@calimero.vinschen.de> (raw)
In-Reply-To: <3e5ea337-8748-7c1c-813d-29196b6ef68a@maxrnd.com>
On Dec 8 01:43, Mark Geisert wrote:
> Takashi Yano wrote:
> [...]
> > I think the following patch makes the intent clearer.
> > What do you think?
> >
> >
> > From d0aee9af225384a24ac6301f987ce2e94f262500 Mon Sep 17 00:00:00 2001
> > From: Takashi Yano <takashi.yano@nifty.ne.jp>
> > Date: Wed, 8 Dec 2021 17:06:03 +0900
> > Subject: [PATCH] Cygwin: clipboard: Make intent of the code clearer.
> >
> > ---
> > winsup/cygwin/fhandler_clipboard.cc | 4 ++--
> > winsup/cygwin/include/sys/clipboard.h | 1 +
> > 2 files changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/winsup/cygwin/fhandler_clipboard.cc b/winsup/cygwin/fhandler_clipboard.cc
> > index 05f54ffb3..65a3cad97 100644
> > --- a/winsup/cygwin/fhandler_clipboard.cc
> > +++ b/winsup/cygwin/fhandler_clipboard.cc
> > @@ -76,7 +76,7 @@ fhandler_dev_clipboard::set_clipboard (const void *buf, size_t len)
> > clipbuf->cb_sec = clipbuf->ts.tv_sec;
> > #endif
> > clipbuf->cb_size = len;
> > - memcpy (&clipbuf[1], buf, len); // append user-supplied data
> > + memcpy (clipbuf->data, buf, len); // append user-supplied data
> > GlobalUnlock (hmem);
> > EmptyClipboard ();
> > @@ -229,7 +229,7 @@ fhandler_dev_clipboard::read (void *ptr, size_t& len)
> > if (pos < (off_t) clipbuf->cb_size)
> > {
> > ret = (len > (clipbuf->cb_size - pos)) ? clipbuf->cb_size - pos : len;
> > - memcpy (ptr, (char *) (clipbuf + 1) + pos, ret);
> > + memcpy (ptr, clipbuf->data + pos, ret);
> > pos += ret;
> > }
> > }
> > diff --git a/winsup/cygwin/include/sys/clipboard.h b/winsup/cygwin/include/sys/clipboard.h
> > index 4c00c8ea1..b2544be85 100644
> > --- a/winsup/cygwin/include/sys/clipboard.h
> > +++ b/winsup/cygwin/include/sys/clipboard.h
> > @@ -44,6 +44,7 @@ typedef struct
> > };
> > };
> > uint64_t cb_size; // 8 bytes everywhere
> > + char data[];
> > } cygcb_t;
> > #endif
>
> Sigh. I guess it's not possible to keep rid of a data item like I'd hoped.
> At least "data[]" is cleaner than the historical "data[1]" here. If you
> call the item cb_data I can live with it.
> Thanks all for the discussion.
sometype *ptr;
ptr = (sometype *) somebuffer;
do_something (ptr + 1);
is a perfectly valid and perfectly readable thing, and used a lot if
"sometype" is either a header in a buffer followed by arbitrary data, or
if the buffer consists of multiple packed blocks of type "sometype".
Takashi's suggestion adds the information that "sometype" is a header
followed by arbitrary data, so that's a good thing..
Corinna
next prev parent reply other threads:[~2021-12-08 10:19 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-07 14:00 Takashi Yano
2021-12-07 14:23 ` Corinna Vinschen
2021-12-07 20:18 ` Thomas Wolff
2021-12-08 5:53 ` Brian Inglis
2021-12-08 6:30 ` Mark Geisert
2021-12-08 7:24 ` Brian Inglis
2021-12-08 8:19 ` Takashi Yano
2021-12-08 9:43 ` Mark Geisert
2021-12-08 10:19 ` Corinna Vinschen [this message]
2021-12-08 18:46 ` Thomas Wolff
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YbCGmbAsZ4pJuttS@calimero.vinschen.de \
--to=corinna-cygwin@cygwin.com \
--cc=cygwin-patches@cygwin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).