diff options
| author | Ben Straub <bs@github.com> | 2012-11-30 16:31:42 -0800 |
|---|---|---|
| committer | Ben Straub <bs@github.com> | 2012-11-30 16:31:42 -0800 |
| commit | c7231c45fecf6c0ae91815a82db7e98c94689497 (patch) | |
| tree | 33426a5463917d64b1f160f8083f3dfbd4217fe3 /src/common.h | |
| parent | 4ec197f3049d203739066e0c2d2c5c39f78fd808 (diff) | |
| download | libgit2-c7231c45fecf6c0ae91815a82db7e98c94689497.tar.gz | |
Deploy GITERR_CHECK_VERSION
Diffstat (limited to 'src/common.h')
| -rw-r--r-- | src/common.h | 17 |
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" |
