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

Re: segmentation fault (nullpointer) with git log --submodule -p

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 25, 2013, 07:27 UTC
Message-ID
<7vr4l967u2.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20130125055331.GC26524@elie.Belkin>
Jonathan Nieder <jrnieder@gmail.com> writes:
Show 7 quoted lines
> Hi,
>
> Junio C Hamano wrote:
>
>> I've been toying with an idea along this line.
>
> Heh.  Just for fun, here's an uglier version:
Much nicer, though.
Show 49 quoted lines
>
> 	struct wcb_data {
> 		int had_buffer;
> 		int using_buffer;
> 	};
> 	#define WITH_COMMIT_BUFFER_DATA_INIT { 0, 0 }
>
> 	extern void acquire_commit_buffer(struct commit *, struct wcb_data *);
> 	extern void done_with_commit_buffer(struct commit *, struct wcb_data *);
>
> 	/*
> 	 * usage:
> 	 *	struct wcb_data buf = WITH_COMMIT_BUFFER_INIT;
> 	 *
> 	 *	with_commit_buffer(commit, buf) {
> 	 *		...
> 	 *	}
> 	 */
> 	#define with_commit_buffer(commit, i) \
> 		for (acquire_commit_buffer(commit, &i); \
> 		     i.using_buffer; \
> 		     done_with_commit_buffer(commit, &i))
>
> 	void acquire_commit_buffer(struct commit *commit, struct wcb_data *i)
> 	{
> 		enum object_type type;
> 		unsigned long size;
>
> 		assert(!i->using_buffer);
> 		i->using_buffer = 1;
> 		i->had_buffer = !!commit->buffer;
>
> 		if (i->had_buffer)
> 			return;
> 		commit->buffer = read_sha1_file(commit->object.sha1, &type, &size);
> 		if (!commit->buffer)
> 			die("unable to read commit %s", sha1_to_hex(commit->object.sha1));
> 	}
>
> 	void done_with_commit_buffer(struct commit *commit, struct wcb_data *i)
> 	{
> 		assert(i->using_buffer);
> 		i->using_buffer = 0;
>
> 		if (!i->had_buffer) {
> 			free(commit->buffer);
> 			commit->buffer = NULL;
> 		}
> 	}
Previous: Jonathan NiederNext: Jonathon Mah
Message 15 of 24 in “segmentation fault (nullpointer) with git log --submodule -p”
  1. ArminJan 23, 2013
  2. Jeff KingJan 23, 2013
  3. Stefan NäweJan 24, 2013
  4. Duy NguyenJan 24, 2013
  5. Stefan NäweJan 24, 2013
  6. Duy NguyenJan 24, 2013
  7. Jeff KingJan 24, 2013
  8. Junio C HamanoJan 24, 2013
  9. Jeff KingJan 25, 2013
  10. Duy NguyenJan 25, 2013
  11. Junio C HamanoJan 25, 2013
  12. Jeff KingJan 25, 2013
  13. Junio C HamanoJan 25, 2013
  14. Jonathan NiederJan 25, 2013
  15. Junio C HamanoJan 25, 2013
  16. Jonathon MahJan 25, 2013
  17. Junio C HamanoJan 25, 2013
  18. 0/3 lazily load commit->bufferJeff King, Jan 26, 2013
  19. 1/3 commit: drop useless xstrdup of commit messageJeff King, Jan 26, 2013
  20. 2/3 logmsg_reencode: never return NULLJeff King, Jan 26, 2013
  21. 3/3 logmsg_reencode: lazily load missing commit buffersJeff King, Jan 26, 2013
  22. Junio C HamanoJan 26, 2013
  23. Jeff KingJan 26, 2013
  24. Junio C HamanoJan 27, 2013

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.