File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed
generate/templates/manual/src Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -24,10 +24,17 @@ git_strarray *StrArrayConverter::Convert(Handle<v8::Value> val) {
2424 }
2525}
2626
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+
2736git_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 ());
3138
3239 for (size_t i = 0 ; i < result->count ; i++) {
3340 NanUtf8String entry (val->Get (i));
@@ -47,9 +54,7 @@ git_strarray* StrArrayConverter::ConvertString(Handle<String> val) {
4754}
4855
4956git_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);
5358
5459 for (size_t i = 0 ; i < result->count ; i++) {
5560 result->strings [i] = strdup (argv[i]);
You can’t perform that action at this time.
0 commit comments