diff mbox

[U-Boot,05/17] stdio: remove useless strncpy

Message ID 1351902453-27956-6-git-send-email-sjg@chromium.org
State Superseded, archived
Delegated to: Tom Rini
Headers show

Commit Message

Simon Glass Nov. 3, 2012, 12:27 a.m. UTC
From: Vincent Palatin <vpalatin@chromium.org>

The name is already copied when we memopy the whole structure.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>

Commit-Ready: Vincent Palatin <vpalatin@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
---
 common/stdio.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

Comments

Wolfgang Denk Nov. 3, 2012, 3:31 p.m. UTC | #1
Dear Simon Glass,

In message <1351902453-27956-6-git-send-email-sjg@chromium.org> you wrote:
> From: Vincent Palatin <vpalatin@chromium.org>
> 
> The name is already copied when we memopy the whole structure.

memopy?

> --- a/common/stdio.c
> +++ b/common/stdio.c
> @@ -135,7 +135,6 @@ struct stdio_dev* stdio_clone(struct stdio_dev *dev)
>  		return NULL;
>  
>  	memcpy(_dev, dev, sizeof(struct stdio_dev));
> -	strncpy(_dev->name, dev->name, 16);

_dev contains just the pointer, not the data, so why can we omit
copying the data?

Best regards,

Wolfgang Denk
Simon Glass Nov. 15, 2012, 10:25 p.m. UTC | #2
Hi Wolfgang,

On Sat, Nov 3, 2012 at 8:31 AM, Wolfgang Denk <wd@denx.de> wrote:
> Dear Simon Glass,
>
> In message <1351902453-27956-6-git-send-email-sjg@chromium.org> you wrote:
>> From: Vincent Palatin <vpalatin@chromium.org>
>>
>> The name is already copied when we memopy the whole structure.
>
> memopy?
>

Done

>> --- a/common/stdio.c
>> +++ b/common/stdio.c
>> @@ -135,7 +135,6 @@ struct stdio_dev* stdio_clone(struct stdio_dev *dev)
>>               return NULL;
>>
>>       memcpy(_dev, dev, sizeof(struct stdio_dev));
>> -     strncpy(_dev->name, dev->name, 16);
>
> _dev contains just the pointer, not the data, so why can we omit
> copying the data?

I will add more detail to the commit message:

    This is because struct stdio_dev has this field:

        char    name[16];               /* Device name
         */

    So the data is inline, rather than being a pointer.


>
> Best regards,
>
> Wolfgang Denk
>
> --
> DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de
> "It is better for civilization to be going down the drain than to  be
> coming up it."                                          - Henry Allen

Regards,
Simon
diff mbox

Patch

diff --git a/common/stdio.c b/common/stdio.c
index 605ff3f..c7a323f 100644
--- a/common/stdio.c
+++ b/common/stdio.c
@@ -135,7 +135,6 @@  struct stdio_dev* stdio_clone(struct stdio_dev *dev)
 		return NULL;
 
 	memcpy(_dev, dev, sizeof(struct stdio_dev));
-	strncpy(_dev->name, dev->name, 16);
 
 	return _dev;
 }