summaryrefslogtreecommitdiff
path: root/src/common.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common.h')
-rw-r--r--src/common.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/common.h b/src/common.h
index a35239e3d..b779d2800 100644
--- a/src/common.h
+++ b/src/common.h
@@ -65,6 +65,23 @@ void giterr_set(int error_class, const char *string, ...);
*/
void giterr_set_regex(const regex_t *regex, int error_code);
+/**
+ * Check a versioned structure for validity
+ */
+GIT_INLINE(bool) giterr__check_version(const void *structure, unsigned int expected_max, const char *name)
+{
+ if (!structure)
+ return true;
+
+ unsigned int actual = *(unsigned int*)structure;
+ if (actual > 0 && actual <= expected_max)
+ return true;
+
+ giterr_set(GITERR_INVALID, "Invalid version %d on %s", actual, name);
+ return false;
+}
+#define GITERR_CHECK_VERSION(S,V,N) if (!giterr__check_version(S,V,N)) return -1
+
/* NOTE: other giterr functions are in the public errors.h header file */
#include "util.h"