On 8/28/14 6:58, Chen Gang wrote: > On 08/28/2014 06:51 AM, Konstantin Serebryany wrote: >> But, what makes you think there is a bug here? >> The comment in sanitizer_common/sanitizer_common.h says: >> // name should have space for at least max_len+1 bytes. >> > > Oh, really, but for me, I still prefer to let max_len as all real buffer > length which like common sense (especially for extern functions). > > If this extern function is not real used, at present (but will be used > next), for me, I still want to improve it (about max_len).
In the current gcc source code, it is not used, but I guess, it may be used, next. Theoretically, we can treate all extern functions as API, which need be more careful about its declarations (include parameters definition), or may borther many callers: - If caller has duty to be sure of '\0' terminated (e.g. strncpy), callee need not care about it. For our case, need remove "name[max_len] = 0;". - If callee has duty to be sure of '\0' terminated (snprintf, gets), caller need not care about it. For our case, need use "max_len - 1" instead of "max_len". For me, the extern function is neccesary to be improved in time (before it is used by others). Or as an API, it is hard to be changed again. Thanks. -- Chen Gang Open, share, and attitude like air, water, and life which God blessed