summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorlhchavez <lhchavez@lhchavez.com>2021-02-23 19:33:34 -0800
committerlhchavez <lhchavez@lhchavez.com>2021-08-08 19:08:59 -0700
commit231ca4fad36ce7b3dd5d79b599be46ab6001fc18 (patch)
tree6616d81c71b873f122134f046073defcc4f659c2 /src
parent9eb17d460cd681bbc14d56ed8fdf440bc69b5456 (diff)
downloadlibgit2-231ca4fad36ce7b3dd5d79b599be46ab6001fc18.tar.gz
Proof-of-concept for a more aggressive GIT_UNUSED()
This adds a `-Wunused-result`-proof `GIT_UNUSED()`, just to demonstrate that it works. With this, sortedcache.h is now completely `GIT_WARN_UNUSED_RESULT`-annotated!
Diffstat (limited to 'src')
-rw-r--r--src/cc-compat.h10
-rw-r--r--src/odb.c4
-rw-r--r--src/refdb_fs.c6
-rw-r--r--src/sortedcache.h3
4 files changed, 16 insertions, 7 deletions
diff --git a/src/cc-compat.h b/src/cc-compat.h
index de1469da8..21f321124 100644
--- a/src/cc-compat.h
+++ b/src/cc-compat.h
@@ -43,7 +43,15 @@
# define GIT_ALIGN(x,size) x
#endif
-#define GIT_UNUSED(x) ((void)(x))
+#if defined(__GNUC__)
+# define GIT_UNUSED(x) \
+ do { \
+ typeof(x) _unused __attribute__((unused)); \
+ _unused = (x); \
+ } while (0)
+#else
+# define GIT_UNUSED(x) ((void)(x))
+#endif
/* Define the printf format specifier to use for size_t output */
#if defined(_MSC_VER) || defined(__MINGW32__)
diff --git a/src/odb.c b/src/odb.c
index 22c8c8c87..e3a5381e6 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -573,7 +573,7 @@ int git_odb__add_default_backends(
git_odb *db, const char *objects_dir,
bool as_alternates, int alternate_depth)
{
- size_t i;
+ size_t i = 0;
struct stat st;
ino_t inode;
git_odb_backend *loose, *packed;
@@ -582,7 +582,7 @@ int git_odb__add_default_backends(
* a cross-platform workaround for this */
#ifdef GIT_WIN32
GIT_UNUSED(i);
- GIT_UNUSED(st);
+ GIT_UNUSED(&st);
inode = 0;
#else
diff --git a/src/refdb_fs.c b/src/refdb_fs.c
index 0b8e103c2..82977cc2c 100644
--- a/src/refdb_fs.c
+++ b/src/refdb_fs.c
@@ -122,7 +122,7 @@ static int packed_reload(refdb_fs_backend *backend)
*/
if (error <= 0) {
if (error == GIT_ENOTFOUND) {
- git_sortedcache_clear(backend->refcache, true);
+ GIT_UNUSED(git_sortedcache_clear(backend->refcache, true));
git_error_clear();
error = 0;
}
@@ -131,7 +131,7 @@ static int packed_reload(refdb_fs_backend *backend)
/* At this point, refresh the packed refs from the loaded buffer. */
- git_sortedcache_clear(backend->refcache, false);
+ GIT_UNUSED(git_sortedcache_clear(backend->refcache, false));
scan = (char *)packedrefs.ptr;
eof = scan + packedrefs.size;
@@ -219,7 +219,7 @@ static int packed_reload(refdb_fs_backend *backend)
parse_failed:
git_error_set(GIT_ERROR_REFERENCE, "corrupted packed references file");
- git_sortedcache_clear(backend->refcache, false);
+ GIT_UNUSED(git_sortedcache_clear(backend->refcache, false));
git_sortedcache_wunlock(backend->refcache);
git_buf_dispose(&packedrefs);
diff --git a/src/sortedcache.h b/src/sortedcache.h
index eb74be9e5..777b28bda 100644
--- a/src/sortedcache.h
+++ b/src/sortedcache.h
@@ -133,7 +133,8 @@ void git_sortedcache_updated(git_sortedcache *sc);
* If `wlock` is true, grabs write lock and releases when done, otherwise
* you should already be holding a write lock when you call this.
*/
-int git_sortedcache_clear(git_sortedcache *sc, bool wlock);
+GIT_WARN_UNUSED_RESULT int git_sortedcache_clear(
+ git_sortedcache *sc, bool wlock);
/* Find and/or insert item, returning pointer to item data.
* You should already be holding the write lock when you call this.