8000 Clean up some error handling and change callback error behavior by arrbee · Pull Request #1986 · libgit2/libgit2 · GitHub
[go: up one dir, main page]

Skip to content

Clean up some error handling and change callback error behavior #1986

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Dec 13, 2013
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9f77b3f
Add config read fns with controlled error behavior
arrbee Nov 25, 2013
96869a4
Improve GIT_EUSER handling
arrbee Dec 4, 2013
dab89f9
Further EUSER and error propagation fixes
arrbee Dec 5, 2013
fcd324c
Add git_vector_free_all
arrbee Dec 6, 2013
25e0b15
Remove converting user error to GIT_EUSER
arrbee Dec 6, 2013
6005801
Fix C99 __func__ for MSVC
arrbee Dec 6, 2013
c7b3e1b
Some callback error check style cleanups
arrbee Dec 6, 2013
f10d7a3
Further callback error check style fixes
arrbee Dec 6, 2013
26c1cb9
One more rename/cleanup for callback err functions
arrbee Dec 9, 2013
373cf6a
Update docs for new callback return value behavior
arrbee Dec 9, 2013
19853bd
Update git_blob_create_fromchunks callback behavr
< 8000 span class="description"> arrbee Dec 10, 2013
cbd0489
Fix checkout notify callback docs and tests
arrbee Dec 10, 2013
8f1066a
Update clone doc and tests for callback return val
arrbee Dec 11, 2013
8046b26
Try a test that won't assert on Linux
arrbee Dec 11, 2013
8b22d86
More improvements to callback return value tests
arrbee Dec 11, 2013
7697e54
Test cancel from indexer progress callback
arrbee Dec 11, 2013
7e3ed41
Fix up some valgrind leaks and warnings
arrbee Dec 12, 2013
11bd7a0
More tests of canceling from callbacks
arrbee Dec 12, 2013
9cfce27
Cleanups, renames, and leak fixes
arrbee Dec 12, 2013
452c7de
Add git_treebuilder_insert test and clarify doc
arrbee Dec 12, 2013
ce33645
pool: Cleanup error handling in pool_strdup
vmg Dec 13, 2013
437f7d6
pool: Correct overflow checks
vmg Dec 13, 2013
7a16d54
pool: Agh, this test doesn't really apply in 32-bit machines
vmg Dec 13, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
pool: Cleanup error handling in pool_strdup
Note that `git_pool_strdup` cannot really return any error codes,
 because the pool doesn't set errors on OOM.

 The only place where `giterr_set_oom` is called is in
 `git_pool_strndup`, in a conditional check that is always optimized
 away. `n + 1` cannot be zero if `n` is unsigned because the compiler
 doesn't take wraparound into account.

 This check has been removed altogether because `size_t` is not
 particularly going to overflow.
  • Loading branch information
vmg committed Dec 13, 2013
commit ce33645ff32d68dfd89867468f58fd9c245c26ff
19 changes: 4 additions & 15 deletions src/pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,19 +190,15 @@ void *git_pool_malloc(git_pool *pool, uint32_t items)

char *git_pool_strndup(git_pool *pool, const char *str, size_t n)
{
void *ptr = NULL;
char *ptr = NULL;

assert(pool && str && pool->item_size == sizeof(char));

if (n + 1 == 0) {
giterr_set_oom();
return NULL;
}

if ((ptr = git_pool_malloc(pool, (uint32_t)(n + 1))) != NULL) {
memcpy(ptr, str, n);
*(((char *)ptr) + n) = '\0';
ptr[n] = '\0';
}

pool->has_string_alloc = 1;

return ptr;
Expand All @@ -217,14 +213,7 @@ char *git_pool_strdup(git_pool *pool, const char *str)

char *git_pool_strdup_safe(git_pool *pool, const char *str)
{
if (!str)
return NULL;
else {
char *result = git_pool_strdup(pool, str);
if (!result)
giterr_clear();
return result;
}
return str ? git_pool_strdup(pool, str) : NULL;
}

char *git_pool_strcat(git_pool *pool, const char *a, const char *b)
Expand Down
0