qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: Denis Plotnikov <dplotnikov@virtuozzo.com>,
	Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
	"kwolf@redhat.com" <kwolf@redhat.com>
Cc: "qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
	"qemu-block@nongnu.org" <qemu-block@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH v6] qemu-io: add pattern file for write command
Date: Thu, 11 Jul 2019 15:07:46 +0200	[thread overview]
Message-ID: <c8293553-a410-27e7-4794-03adcfc91cea@redhat.com> (raw)
In-Reply-To: <973ca865-83ee-5dd0-5c36-906cab220fe9@virtuozzo.com>


[-- Attachment #1.1: Type: text/plain, Size: 1575 bytes --]

On 27.06.19 17:26, Denis Plotnikov wrote:
> 
> 
> On 19.06.2019 13:09, Vladimir Sementsov-Ogievskiy wrote:
>> 10.06.2019 16:21, Denis Plotnikov wrote:
>>> The patch allows to provide a pattern file for write
>>> command. There was no similar ability before.
>>>
>>> Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com>
>>> ---
>>> v6:
>>>     * the pattern file is read once to reduce io
>>>
>>> v5:
>>>     * file name initiated with null to make compilers happy
>>>
>>> v4:
>>>     * missing signed-off clause added
>>>
>>> v3:
>>>     * missing file closing added
>>>     * exclusive flags processing changed
>>>     * buffer void* converted to char* to fix pointer arithmetics
>>>     * file reading error processing added
>>> ---
>>>    qemu-io-cmds.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++----
>>>    1 file changed, 82 insertions(+), 6 deletions(-)

[...]

>>> +    if (l < len) {
>>> +        char *file_buf = g_malloc(sizeof(char) * l);

Note that sizeof(char) is guaranteed to be 1.

(C1x standard, 6.5.3.4, paragraph 4.)

>>> +        memcpy(file_buf, buf, l);
>>
>> I see no reason to copy it, you can just use buf_origin pointer
>> instead.
> I use buf_origin to save the beginning pointer to return it from the 
> function avoiding later calculation of the beginning address since 
> pointer of the buf is changed in the loop.

The point is that you don’t need file_buf.  You can drop it, replace all
occurrences of file_buf by buf_origin, and probably use memmove instead
of memcpy.

Max


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

      reply	other threads:[~2019-07-11 13:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-10 13:21 [Qemu-devel] [PATCH v6] qemu-io: add pattern file for write command Denis Plotnikov
2019-06-19 10:09 ` Vladimir Sementsov-Ogievskiy
2019-06-27 15:26   ` Denis Plotnikov
2019-07-11 13:07     ` Max Reitz [this message]

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=c8293553-a410-27e7-4794-03adcfc91cea@redhat.com \
    --to=mreitz@redhat.com \
    --cc=dplotnikov@virtuozzo.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=vsementsov@virtuozzo.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 NNTP newsgroup(s).