[U-Boot-Users] [PATCH] TFTP: add host ip addr support

Ben Warren
2008-01-16T21:38:34Z

Wolfgang Denk wrote:
> In message <478E6D5A.4070807@gmail.com> you wrote:
>
>> #define MAX_LEN 80
>> static char tftp_filename[MAX_LEN + 1];
>> memset(tftp_filename[MAX_LEN], 0, 1);
>>
>
> warning: passing argument 1 of 'memset' makes pointer from integer without a cast
>
>
10-second response, brain not fully engaged. Compiler not used (duh?)
>> strncpy(tftp_filename, str, MAX_LEN);
>>
>>
>> Better?
>>
>
> No, definitely not.
>
> First, the compiler will issue a warning; second, using memcpy() to
> store a single character is serious overkill - why don't you simply
> use "tftp_filename[MAX_LEN] = '\0';" ?;and third - the real bug - the
> strncpy will happily overwrite the 0 you placed there before.
>
>
strncpy won't touch the zero, since it's in the 81st byte and strncpy
will only copy 80. True about the warnings and memset overkill, though.

OK, let's move on...

Jean-Christophe - Jason McMullen has given you a nice prototype. Please
use it.

regards,
Ben