Subject: Re: [Suggestion] net/atm : for sprintf, need check the total write length whether larger than a page.

From: Chen Gang <[email-masked]>
Date: Thu, 06 Dec 2012 17:05:06 +0800

Hi Chas Williams:

  all of my original reply are my idea (or suggestions), not for issues.

  if you do not need them, please help to send patch.

  I have tried to check it. at least, I did not find issues (and I also
also learned from it)

  hope the patch can pass reviewers checking !

  Good Luck !

  :-)

gchen.

于 2012年12月06日 09:15, Chen Gang 写道:
> 于 2012年12月05日 22:55, chas williams - CONTRACTOR 写道:
>> On Wed, 05 Dec 2012 13:59:26 +0800
>>
>> it doesn't seem like optimizing for this corner case is a huge
>> concern.  the list cannot be infinitely long.
>>
> 
>   ok.
> 
> 
>>>>>
>>>>> By the way:
>>>>>   will it be better that always let "\n" at the end ?
>>>>>   (if count == PAGE_SIZE in a loop, we can not let "\n" at the end).
>>>>
>>>>    oh, sorry ! count will never >= PAGE_SIZE.
>>>>
>>>>    I think let "PAGE_SIZE - 2" instead of "PAGE_SIZE" in the loop, so we
>>>> can make the room for the end of "\n".
>>>>
>>>>
>>>>
>>>    sorry, "PAGE_SIZE - 1" is enough, not need "PAGE_SIZE - 2".
>>
>> did you mean '\0' instead of '\n'?  scnprintf() considers the trailing
>> '\0' when formatting.
> 
>   no, originally, the end is "\n\0".
> 
>   I prefer we still compatible "\n" when the contents are very large.
>   if count already == (PAGE_SIZE - 1), we have no chance to append "\n" to the end.
> 
> -		pos += sprintf(pos, "\n");
> +		count += scnprintf(buf + count, PAGE_SIZE - count, "\n");
> 
> 
>> --
>> To unsubscribe from this list: send the line "unsubscribe netdev" in
>> the body of a message to [email-masked]
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>
>>
> 
> 

-- 
Chen Gang

Asianux Corporation