linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Szymon Janc <szymon.janc@tieto.com>
To: Bharat Panda <bharat.panda@samsung.com>
Cc: linux-bluetooth@vger.kernel.org, cpgs@samsung.com
Subject: Re: [PATCH ] unit: Use g_memdup replacing g_malloc0+memcpy
Date: Fri, 29 May 2015 16:40:23 +0200	[thread overview]
Message-ID: <2675140.GJPQpNdFbz@leonov> (raw)
In-Reply-To: <1432900090-20152-1-git-send-email-bharat.panda@samsung.com>

Hi Bharat,

On Friday 29 of May 2015 17:18:10 Bharat Panda wrote:
> Replace use of g_malloc0+memcpy with g_memdup.
> ---
>  unit/test-gattrib.c | 3 +--
>  unit/test-sdp.c     | 4 +---
>  2 files changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/unit/test-gattrib.c b/unit/test-gattrib.c
> index 416e596..d9c52d7 100644
> --- a/unit/test-gattrib.c
> +++ b/unit/test-gattrib.c
> @@ -224,8 +224,7 @@ static void result_canary(guint8 status, const guint8
> *pdu, guint16 len, struct result_data *result = data;
> 
>  	result->status = status;
> -	result->pdu = g_malloc0(len);
> -	memcpy(result->pdu, pdu, len);
> +	result->pdu = g_memdup(pdu, len);
>  	result->len = len;
> 
>  	if (g_test_verbose())
> diff --git a/unit/test-sdp.c b/unit/test-sdp.c
> index b4ef4d1..58d90f8 100644
> --- a/unit/test-sdp.c
> +++ b/unit/test-sdp.c
> @@ -189,9 +189,7 @@ static gboolean send_pdu(gpointer user_data)
> 
>  	pdu_len = req_pdu->raw_size + context->cont_size;
> 
> -	buf = g_malloc0(pdu_len);
> -
> -	memcpy(buf, req_pdu->raw_data, req_pdu->raw_size);
> +	buf = g_memdup(req_pdu->raw_data, req_pdu->raw_size);

This is not correct. If context->cont_size > 0 then you write after allocated 
memory (see line below).

>  	if (context->cont_size > 0)
>  		memcpy(buf + req_pdu->raw_size, context->cont_data,

-- 
BR
Szymon Janc

  reply	other threads:[~2015-05-29 14:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-29 11:48 [PATCH ] unit: Use g_memdup replacing g_malloc0+memcpy Bharat Panda
2015-05-29 14:40 ` Szymon Janc [this message]
2015-05-29 14:56   ` Bharat Bhusan Panda
2015-05-29 15:25     ` Szymon Janc
2015-06-01 10:39       ` Bharat Bhusan Panda

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=2675140.GJPQpNdFbz@leonov \
    --to=szymon.janc@tieto.com \
    --cc=bharat.panda@samsung.com \
    --cc=cpgs@samsung.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /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).