Wolfgang Denk wrote:
> In message <[EMAIL PROTECTED]> you wrote:
>   
>>> But I diaagree about strncpy because you need to known the size of
>>> the string and we know it only when we use the default_filename otherwise
>>> we need to strlen and in this strcpy do every thing itself.
>>>
>>>   
>>>       
>> strncpy copies AT MOST 'n' bytes.
>>     
>
> ...and doesn't necessarily NUL-terminate.
>
>   
>> #define MAX_FILE_NAME_LEN 80
>> static char tftp_filename[MAX_FILE_NAME_LEN];
>>
>> strncpy(tftp_filename, str, MAX_FILE_NAME_LEN);
>>
>> Standard buffer overrun protection.
>>     
>
> ...only if you make sure that tftp_filename[] gets terminated
> independent of the length; otherwise you fix the problem when writing
> the srting but create one when reading it.
>
> Best regards,
>
> Wolfgang Denk
>
>   
#define MAX_LEN 80
static char tftp_filename[MAX_LEN + 1];
memset(tftp_filename[MAX_LEN], 0, 1);

strncpy(tftp_filename, str, MAX_LEN);


Better?

regards,
Ben

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
U-Boot-Users mailing list
U-Boot-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/u-boot-users

Reply via email to