Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
3f53c971
Commit
3f53c971
authored
May 05, 2011
by
Vicent Marti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
errors: Set error messages on memory allocation
parent
02f9e637
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
11 deletions
+36
-11
src/common.h
+2
-2
src/util.h
+34
-9
No files found.
src/common.h
View file @
3f53c971
...
@@ -50,12 +50,12 @@ typedef SSIZE_T ssize_t;
...
@@ -50,12 +50,12 @@ typedef SSIZE_T ssize_t;
#include "git2/common.h"
#include "git2/common.h"
#include "git2/types.h"
#include "git2/types.h"
#include "util.h"
#include "thread-utils.h"
#include "thread-utils.h"
#include "bswap.h"
#include "bswap.h"
#define GIT_PATH_MAX 4096
#define GIT_PATH_MAX 4096
extern
int
git__error
(
int
error
,
const
char
*
,
...)
GIT_FORMAT_PRINTF
(
2
,
3
);
extern
int
git__error
(
int
error
,
const
char
*
,
...)
GIT_FORMAT_PRINTF
(
2
,
3
);
#include "util.h"
#endif
/* INCLUDE_common_h__ */
#endif
/* INCLUDE_common_h__ */
src/util.h
View file @
3f53c971
...
@@ -6,16 +6,41 @@
...
@@ -6,16 +6,41 @@
#define MSB(x, bits) ((x) & (~0ULL << (bitsizeof(x) - (bits))))
#define MSB(x, bits) ((x) & (~0ULL << (bitsizeof(x) - (bits))))
/*
/*
* Don't wrap malloc/calloc.
* Custom memory allocation wrappers
* Use the default versions in glibc, and make
* that set error code and error message
* sure that any methods that allocate memory
* on allocation failure
* return a GIT_ENOMEM error when allocation
* fails.
*/
*/
#define git__malloc malloc
GIT_INLINE
(
void
*
)
git__malloc
(
size_t
len
)
#define git__calloc calloc
{
#define git__realloc realloc
void
*
ptr
=
malloc
(
len
);
#define git__strdup strdup
if
(
!
ptr
)
git__error
(
GIT_ENOMEM
,
"Out of memory. Failed to allocate %d bytes."
,
(
int
)
len
);
return
ptr
;
}
GIT_INLINE
(
void
*
)
git__calloc
(
size_t
nelem
,
size_t
elsize
)
{
void
*
ptr
=
calloc
(
nelem
,
elsize
);
if
(
!
ptr
)
git__error
(
GIT_ENOMEM
,
"Out of memory. Failed to allocate %d bytes."
,
(
int
)
elsize
);
return
ptr
;
}
GIT_INLINE
(
char
*
)
git__strdup
(
const
char
*
str
)
{
char
*
ptr
=
strdup
(
str
);
if
(
!
ptr
)
git__error
(
GIT_ENOMEM
,
"Out of memory. Failed to duplicate string"
);
return
ptr
;
}
GIT_INLINE
(
void
*
)
git__realloc
(
void
*
ptr
,
size_t
size
)
{
void
*
new_ptr
=
realloc
(
ptr
,
size
);
if
(
!
new_ptr
)
git__error
(
GIT_ENOMEM
,
"Out of memory. Failed to allocate %d bytes."
,
(
int
)
size
);
return
new_ptr
;
}
extern
int
git__fmt
(
char
*
,
size_t
,
const
char
*
,
...)
extern
int
git__fmt
(
char
*
,
size_t
,
const
char
*
,
...)
GIT_FORMAT_PRINTF
(
3
,
4
);
GIT_FORMAT_PRINTF
(
3
,
4
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment