From mboxrd@z Thu Jan 1 00:00:00 1970 From: Anders Kaseorg Subject: =?UTF-8?Q?=5BPATCH_v3_2=2F4=5D_describe=3A_Don=E2=80=99t_use_a_flex_array_in_struct_commit=5Fname?= Date: Thu, 9 Dec 2010 01:43:32 -0500 (EST) Message-ID: References: <20101203084348.GD18202@burratino> <20101206073214.GA3745@burratino> <7vfwu9qvew.fsf@alter.siamese.dyndns.org> <7v7hfjkhfm.fsf@alter.siamese.dyndns.org> Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Cc: Jonathan Nieder , git@vger.kernel.org, =?UTF-8?Q?SZEDER_G=C3=A1bor?= , Kirill Smelkov , Thomas Rast To: Junio C Hamano X-From: git-owner@vger.kernel.org Thu Dec 09 07:43:43 2010 Return-path: Envelope-to: gcvg-git-2@lo.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PQaE9-00060M-LV for gcvg-git-2@lo.gmane.org; Thu, 09 Dec 2010 07:43:41 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754889Ab0LIGnf (ORCPT ); Thu, 9 Dec 2010 01:43:35 -0500 Received: from mail-qw0-f46.google.com ([209.85.216.46]:57423 "EHLO mail-qw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753426Ab0LIGne (ORCPT ); Thu, 9 Dec 2010 01:43:34 -0500 Received: by qwa26 with SMTP id 26so2239287qwa.19 for ; Wed, 08 Dec 2010 22:43:33 -0800 (PST) Received: by 10.224.60.148 with SMTP id p20mr6516632qah.48.1291877013637; Wed, 08 Dec 2010 22:43:33 -0800 (PST) Received: from localhost (LINERVA.MIT.EDU [18.181.0.232]) by mx.google.com with ESMTPS id t35sm972173qco.18.2010.12.08.22.43.32 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 08 Dec 2010 22:43:33 -0800 (PST) X-X-Sender: andersk@dr-wily.mit.edu In-Reply-To: User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: Now add_to_known_names overwrites commit_names in place when multiple tags point to the same commit. This will make it easier to store commit_names in a hash table. Signed-off-by: Anders Kaseorg --- builtin/describe.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-) diff --git a/builtin/describe.c b/builtin/describe.c index 700f740..5b8461d 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -38,7 +38,7 @@ struct commit_name { unsigned prio:2; /* annotated tag = 2, tag = 1, head = 0 */ unsigned name_checked:1; unsigned char sha1[20]; - char path[FLEX_ARRAY]; /* more */ + const char *path; }; static const char *prio_names[] = { "head", "lightweight", "annotated", @@ -85,15 +85,15 @@ static void add_to_known_names(const char *path, struct commit_name *e = commit->util; struct tag *tag = NULL; if (replace_name(e, prio, sha1, &tag)) { - size_t len = strlen(path)+1; - free(e); - e = xmalloc(sizeof(struct commit_name) + len); + if (!e) { + e = xmalloc(sizeof(struct commit_name)); + commit->util = e; + } e->tag = tag; e->prio = prio; e->name_checked = 0; hashcpy(e->sha1, sha1); - memcpy(e->path, path, len); - commit->util = e; + e->path = path; } found_names = 1; } -- 1.7.3.3