Re: [PATCH 1/5] mktag.c: adjust verify_tag parameters
- From
Brandon Casey <casey@nrlssc.navy.mil>
- Date
- May 12, 2008, 15:43 UTC
- Message-ID
- <482865A1.7040207@nrlssc.navy.mil>
- In-Reply-To
- <7vmymw3cst.fsf@gitster.siamese.dyndns.org>
Junio C Hamano wrote:
Show 17 quoted lines
> drafnel@gmail.com writes: > >> From: Brandon Casey <casey@nrlssc.navy.mil> >> >> The size parameter should be a size_t since it is a string length. > > Correct. > >> There is no reason that the buffer argument should not be constant except >> for the nul termination that is performed in the first few lines of this >> function. This is not necessary, since a valid c string must always be >> nul terminated and we can check whether we have exceeded the caller's >> size parameter at the end of parsing the buffer. > > Wait a minute. The point of passing a stringlet as a tuple of <pointer to > the beginning, length> is that you may not have a valid C string to begin > with, isn't it?
I thought it was just to limit the scope of parsing.
Other functions that deal with non-nul-terminated memory segments (like memchr) do not use char*, they instead use void*.
If we want to handle non-nul-terminated memory segments here, we should probably allocate a new string to copy the memory segment into so we can ensure it is nul-terminated. Otherwise we can't use any of the str*() functions safely.
-brandon