| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1a74a2d commit 3d4cecf
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,10 +24,17 @@ git_strarray *StrArrayConverter::Convert(Handle<v8::Value> val) { | |||
| 24 | 24 | } | |
| 25 | 25 | } | |
| 26 | 26 | ||
| 27 | + static git_strarray * AllocGitStrArray(const size_t count) { | ||
| 28 | + const size_t size = sizeof(git_strarray) + (sizeof(char*) * count); | ||
| 29 | + uint8_t* memory = reinterpret_cast<uint8_t*>(malloc(size)); | ||
| 30 | + git_strarray *result = reinterpret_cast<git_strarray *>(memory); | ||
| 31 | + result->count = count; | ||
| 32 | + result->strings = reinterpret_cast<char**>(memory + sizeof(git_strarray)); | ||
| 33 | + return result; | ||
| 34 | + } | ||
| 35 | + | ||
| 27 | 36 | git_strarray *StrArrayConverter::ConvertArray(Array *val) { | |
| 28 | - git_strarray *result = (git_strarray *)malloc(sizeof(git_strarray)); | ||
| 29 | - result->count = val->Length(); | ||
| 30 | - result->strings = (char **)malloc(sizeof(char*) * result->count); | ||
| 37 | + git_strarray *result = AllocGitStrArray(val->Length()); | ||
| 31 | 38 | ||
| 32 | 39 | for(size_t i = 0; i < result->count; i++) { | |
| 33 | 40 | NanUtf8String entry(val->Get(i)); | |
@@ -47,9 +54,7 @@ git_strarray* StrArrayConverter::ConvertString(Handle<String> val) { | |||
| 47 | 54 | } | |
| 48 | 55 | ||
| 49 | 56 | git_strarray *StrArrayConverter::ConstructStrArray(int argc, char** argv) { | |
| 50 | - git_strarray *result = (git_strarray *)malloc(sizeof(git_strarray)); | ||
| 51 | - result->count = argc; | ||
| 52 | - result->strings = (char **)malloc(sizeof(char*) * result->count); | ||
| 57 | + git_strarray *result = AllocGitStrArray(argc); | ||
| 53 | 58 | ||
| 54 | 59 | for(size_t i = 0; i < result->count; i++) { | |
| 55 | 60 | result->strings[i] = strdup(argv[i]); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments