mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-03 15:27:01 +00:00
Introduce git__substrdup
This commit is contained in:
parent
8c36a3cdba
commit
c4beee7681
10
src/netops.c
10
src/netops.c
@ -606,26 +606,26 @@ int gitno_extract_url_parts(
|
|||||||
start = url;
|
start = url;
|
||||||
if (at && at < slash) {
|
if (at && at < slash) {
|
||||||
start = at+1;
|
start = at+1;
|
||||||
*username = git__strndup(url, at - url);
|
*username = git__substrdup(url, at - url);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (colon && colon < at) {
|
if (colon && colon < at) {
|
||||||
git__free(*username);
|
git__free(*username);
|
||||||
*username = git__strndup(url, colon-url);
|
*username = git__substrdup(url, colon-url);
|
||||||
*password = git__strndup(colon+1, at-colon-1);
|
*password = git__substrdup(colon+1, at-colon-1);
|
||||||
colon = strchr(at, ':');
|
colon = strchr(at, ':');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (colon == NULL) {
|
if (colon == NULL) {
|
||||||
*port = git__strdup(default_port);
|
*port = git__strdup(default_port);
|
||||||
} else {
|
} else {
|
||||||
*port = git__strndup(colon + 1, slash - colon - 1);
|
*port = git__substrdup(colon + 1, slash - colon - 1);
|
||||||
}
|
}
|
||||||
GITERR_CHECK_ALLOC(*port);
|
GITERR_CHECK_ALLOC(*port);
|
||||||
|
|
||||||
end = colon == NULL ? slash : colon;
|
end = colon == NULL ? slash : colon;
|
||||||
|
|
||||||
*host = git__strndup(start, end - start);
|
*host = git__substrdup(start, end - start);
|
||||||
GITERR_CHECK_ALLOC(*host);
|
GITERR_CHECK_ALLOC(*host);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
14
src/util.h
14
src/util.h
@ -51,11 +51,7 @@ GIT_INLINE(char *) git__strndup(const char *str, size_t n)
|
|||||||
while (length < n && str[length])
|
while (length < n && str[length])
|
||||||
++length;
|
++length;
|
||||||
|
|
||||||
ptr = (char*)malloc(length + 1);
|
ptr = (char*)git__malloc(length + 1);
|
||||||
if (!ptr) {
|
|
||||||
giterr_set_oom();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (length)
|
if (length)
|
||||||
memcpy(ptr, str, length);
|
memcpy(ptr, str, length);
|
||||||
@ -65,6 +61,14 @@ GIT_INLINE(char *) git__strndup(const char *str, size_t n)
|
|||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* NOTE: This doesn't do null or '\0' checking. Watch those boundaries! */
|
||||||
|
GIT_INLINE(char *) git__substrdup(const char *start, size_t n)
|
||||||
|
{
|
||||||
|
char *ptr = (char*)git__calloc(n+1, sizeof(char));
|
||||||
|
memcpy(ptr, start, n);
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
GIT_INLINE(void *) git__realloc(void *ptr, size_t size)
|
GIT_INLINE(void *) git__realloc(void *ptr, size_t size)
|
||||||
{
|
{
|
||||||
void *new_ptr = realloc(ptr, size);
|
void *new_ptr = realloc(ptr, size);
|
||||||
|
Loading…
Reference in New Issue
Block a user