Subject: Re: [PATCH 03/10] builtin/tag.c: convert trivial snprintf calls to xsnprintf

From: Ramsay Jones <[email-masked]>
Date: Fri, 3 Jun 2016 16:37:52 +0100

On 03/06/16 09:52, Jeff King wrote:
> On Fri, Jun 03, 2016 at 07:47:17AM +0000, Elia Pinto wrote:
> 
>>  builtin/tag.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/builtin/tag.c b/builtin/tag.c
>> index 50e4ae5..0345ca3 100644
>> --- a/builtin/tag.c
>> +++ b/builtin/tag.c
>> @@ -225,7 +225,7 @@ static void create_tag(const unsigned char *object, const char *tag,
>>  	if (type <= OBJ_NONE)
>>  	    die(_("bad object type."));
>>  
>> -	header_len = snprintf(header_buf, sizeof(header_buf),
>> +	header_len = xsnprintf(header_buf, sizeof(header_buf),
>>  			  "object %s\n"
>>  			  "type %s\n"
>>  			  "tag %s\n"
> 
> This is another of my "type 2" cases. I'd argue it should be using a
> heap buffer to handle tag and tagger names of arbitrary size.

Yep. As it stands, the code following this hunk:

        if (header_len > sizeof(header_buf) - 1)
                die(_("tag header too big."));

is now dead code, and the new error message is not as useful.

ATB,
Ramsay Jones