diff options
| author | Vicent Marti <tanoku@gmail.com> | 2010-10-28 02:07:18 +0300 |
|---|---|---|
| committer | Vicent Marti <tanoku@gmail.com> | 2010-10-28 02:07:18 +0300 |
| commit | 585190183b47dc991605abcfbe3afb57220a0f29 (patch) | |
| tree | f8a1f2572f667296a5b5121c64c74bb353557c93 /src/oid.c | |
| parent | 2d16373cb8d8c22b3ec99a6936b82821e99e64a5 (diff) | |
| download | libgit2-585190183b47dc991605abcfbe3afb57220a0f29.tar.gz | |
Fix internal memory management on the library
String mememory is now managed in a much more sane manner.
Fixes include:
- git_person email and name is no longer limited to 64 characters
- git_tree_entry filename is no longer limited to 255 characters
- raw objects are properly opened & closed the minimum amount of
times required for parsing
- unit tests no longer leak
- removed 5 other misc memory leaks as reported by Valgrind
- tree writeback no longer segfaults on rare ocassions
The git_person struct is no longer public. It is now managed by the
library, and getter methods are in place to access its internal
attributes.
Signed-off-by: Vicent Marti <tanoku@gmail.com>
Diffstat (limited to 'src/oid.c')
| -rw-r--r-- | src/oid.c | 35 |
1 files changed, 35 insertions, 0 deletions
@@ -25,6 +25,7 @@ #include "common.h" #include "git/oid.h" +#include "repository.h" #include <string.h> static signed char from_hex[] = { @@ -116,3 +117,37 @@ char *git_oid_to_string(char *out, size_t n, const git_oid *oid) return out; } +int git__parse_oid(git_oid *oid, char **buffer_out, + const char *buffer_end, const char *header) +{ + const size_t sha_len = GIT_OID_HEXSZ; + const size_t header_len = strlen(header); + + char *buffer = *buffer_out; + + if (buffer + (header_len + sha_len + 1) > buffer_end) + return GIT_EOBJCORRUPTED; + + if (memcmp(buffer, header, header_len) != 0) + return GIT_EOBJCORRUPTED; + + if (buffer[header_len + sha_len] != '\n') + return GIT_EOBJCORRUPTED; + + if (git_oid_mkstr(oid, buffer + header_len) < 0) + return GIT_EOBJCORRUPTED; + + *buffer_out = buffer + (header_len + sha_len + 1); + + return 0; +} + +int git__write_oid(git_odb_source *src, const char *header, const git_oid *oid) +{ + char hex_oid[41]; + + git_oid_fmt(hex_oid, oid); + hex_oid[40] = 0; + + return git__source_printf(src, "%s %s\n", header, hex_oid); +} |
