git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 2/3] textconv: support for blame

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 15, 2010, 15:00 UTC
Message-ID
<7vfx0o8hop.fsf@alter.siamese.dyndns.org>
In-Reply-To
<0091febb4a3832a6680a0fbc2209f841@ensimag.fr>
Clément Poulain <clement.poulain@ensimag.imag.fr> writes:
Show 33 quoted lines
> On Mon, 14 Jun 2010 13:40:21 -0700, Junio C Hamano <gitster@pobox.com>
> wrote:
>> Axel Bonnet <axel.bonnet@ensimag.imag.fr> writes:
>> 
>>> @@ -86,16 +87,49 @@ struct origin {
>>> ...
>>> +static void fill_origin_blob(struct diff_options *opt,
>>> +			     struct origin *o, mmfile_t *file)
>>>  {
>>>  	if (!o->file.ptr) {
>>>  		enum object_type type;
>>>  		num_read_blob++;
>>> -		file->ptr = read_sha1_file(o->blob_sha1, &type,
>>> -					   (unsigned long *)(&(file->size)));
>>> +
>>> +		if (DIFF_OPT_TST(opt, ALLOW_TEXTCONV) &&
>>> +		    textconv_object(o->path, o->blob_sha1, &file->ptr,
>>> +				    (size_t *) &file->size))
>> 
>> This cast is not correct, as there is no guarantee that your size_t and
>> typeof(mmfile_t.size) are compatible.  Depending on the gcc version, you
>> would get "dereferencing type-punned pointer will break strict-aliasing
>> rules" error.
>> 
>> The same issue exists in Clément's patch to builtin/cat-file.c.
>
> We did this way because we found a similar cast in prep_temp_blob(),
> diff.c:
>
> 	if (convert_to_working_tree(path,
> 			(const char *)blob, (size_t)size, &buf)) {
>
> where size is an unsigned long.

That is a completely different kind of cast that is sane. The function takes a _value_ of type size_t.

Your cast is "This function wants to store a value to a _memory location_ that is supposed to hold a value of type size_t, and I know &(file->size) is not such a location (it is to hold a value of type 'unsigned long'); please pretend that these two distinct pointers are compatible", which is a big no-no.

Previous: Matthieu MoyNext: Axel Bonnet
Message 14 of 17 in “textconv support for blame”
  1. 0/3 textconv support for blameAxel Bonnet, Jun 7, 2010
  2. 1/3 textconv: make the API publicAxel Bonnet, Jun 7, 2010
  3. 2/3 textconv: support for blameAxel Bonnet, Jun 7, 2010
  4. 3/3 t/t8006: test textconv support for blameAxel Bonnet, Jun 7, 2010
  5. Junio C HamanoJun 11, 2010
  6. Diane GasselinJun 14, 2010
  7. Junio C HamanoJun 11, 2010
  8. Jeff KingJun 12, 2010
  9. Junio C HamanoJun 14, 2010
  10. Clément PoulainJun 15, 2010
  11. Jeff KingJun 15, 2010
  12. bonnetaJun 15, 2010
  13. Matthieu MoyJun 15, 2010
  14. Junio C HamanoJun 15, 2010
  15. 2/3 textconv: support for blameAxel Bonnet, Jun 15, 2010
  16. Jeff KingJun 15, 2010
  17. bonnetaJun 15, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.