diff options
| author | Russell Belfer <arrbee@arrbee.com> | 2012-03-19 16:10:11 -0700 |
|---|---|---|
| committer | Russell Belfer <arrbee@arrbee.com> | 2012-03-19 16:10:11 -0700 |
| commit | 7c7ff7d11e2d22f7b9c7f8152f5c58dde37ac207 (patch) | |
| tree | 838380af916490eb68e3004bc3ec10cc7ac8cf1f /src/util.c | |
| parent | fd7714273cb9646d63f4da8d81450a0f9f9295f5 (diff) | |
| download | libgit2-7c7ff7d11e2d22f7b9c7f8152f5c58dde37ac207.tar.gz | |
Migrate index, oid, and utils to new errors
This includes a few cleanups that came up while converting
these files.
This commit introduces a could new git error classes, including
the catchall class: GITERR_INVALID which I'm using as the class
for invalid and out of range values which are detected at too low
a level of library to use a higher level classification. For
example, an overflow error in parsing an integer or a bad letter
in parsing an OID string would generate an error in this class.
Diffstat (limited to 'src/util.c')
| -rw-r--r-- | src/util.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/util.c b/src/util.c index 679917e36..d0ad47490 100644 --- a/src/util.c +++ b/src/util.c @@ -112,34 +112,40 @@ int git__strtol64(int64_t *result, const char *nptr, const char **endptr, int ba } Return: - if (ndig == 0) - return git__throw(GIT_ENOTNUM, "Failed to convert string to long. Not a number"); + if (ndig == 0) { + giterr_set(GITERR_INVALID, "Failed to convert string to long. Not a number"); + return -1; + } if (endptr) *endptr = p; - if (ovfl) - return git__throw(GIT_EOVERFLOW, "Failed to convert string to long. Overflow error"); + if (ovfl) { + giterr_set(GITERR_INVALID, "Failed to convert string to long. Overflow error"); + return -1; + } *result = neg ? -n : n; - return GIT_SUCCESS; + return 0; } int git__strtol32(int32_t *result, const char *nptr, const char **endptr, int base) { - int error = GIT_SUCCESS; + int error; int32_t tmp_int; int64_t tmp_long; - if ((error = git__strtol64(&tmp_long, nptr, endptr, base)) < GIT_SUCCESS) + if ((error = git__strtol64(&tmp_long, nptr, endptr, base)) < 0) return error; tmp_int = tmp_long & 0xFFFFFFFF; - if (tmp_int != tmp_long) - return git__throw(GIT_EOVERFLOW, "Failed to convert. '%s' is too large", nptr); + if (tmp_int != tmp_long) { + giterr_set(GITERR_INVALID, "Failed to convert. '%s' is too large", nptr); + return -1; + } *result = tmp_int; - + return error; } |
