From ac04bdf6e0ee6bb4286343bc70d745146eb1e506 Mon Sep 17 00:00:00 2001 From: Ramsay Jones Date: Thu, 4 Jun 2009 16:44:54 +0100 Subject: [PATCH] Fix a usage error in a call to the object_file_name() function In 82324ac, the new static function exists_loose() called object_file_name() and, in order to detect an error return, tested for a negative value. This usage is incorrect, as the error return is indicated by a positive return value. (A successful call is indicated by a zero return value) The only error return from object_file_name() relates to insufficient buffer space and the return value gives the required minimum buffer size (which will always be >0). If the caller requires a dynamically allocated buffer, this allows something like the following call sequence: size_t len = object_file_name(NULL, 0, db->object_dir, id); char *buf = git__malloc(len); if (!buf) error(...); object_file_name(buf, len, db->object_dir,id); ... No current callers take advantage of this capability. Fix up the call site and change the return type of the function, from int to size_t, which more accurately reflects the implementation. Signed-off-by: Ramsay Jones Signed-off-by: Andreas Ericsson --- src/odb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/odb.c b/src/odb.c index bd65f47..6b7d1f7 100644 --- a/src/odb.c +++ b/src/odb.c @@ -185,7 +185,7 @@ int git_obj_hash(git_oid *id, git_obj *obj) return GIT_SUCCESS; } -static int object_file_name(char *name, size_t n, char *dir, const git_oid *id) +static size_t object_file_name(char *name, size_t n, char *dir, const git_oid *id) { size_t len = strlen(dir); @@ -860,7 +860,7 @@ static int exists_loose(git_odb *db, const git_oid *id) { char file[GIT_PATH_MAX]; - if (object_file_name(file, sizeof(file), db->objects_dir, id) < 0) + if (object_file_name(file, sizeof(file), db->objects_dir, id)) return 0; if (gitfo_exists(file) < 0) -- 2.11.4.GIT