| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,8 +14,13 @@ | |||
| 14 | 14 | {%if cppClassName == 'String'%} | |
| 15 | 15 | ||
| 16 | 16 | String::Utf8Value {{ name }}(info[{{ jsArg }}]->ToString()); | |
| 17 | + // malloc with one extra byte so we can add the terminating null character C-strings expect: | ||
| 17 | 18 | from_{{ name }} = ({{ cType }}) malloc({{ name }}.length() + 1); | |
| 19 | + // copy the characters from the nodejs string into our C-string (used instead of strdup or strcpy because nulls in | ||
| 20 | + // the middle of strings are valid coming from nodejs): | ||
| 18 | 21 | memcpy((void *)from_{{ name }}, *{{ name }}, {{ name }}.length()); | |
| 22 | + // ensure the final byte of our new string is null, extra casts added to ensure compatibility with various C types | ||
| 23 | + // used in the nodejs binding generation: | ||
| 19 | 24 | memset((void *)(((char *)from_{{ name }}) + {{ name }}.length()), 0, 1); | |
| 20 | 25 | {%elsif cppClassName == 'GitStrarray' %} | |
| 21 | 26 | ||
@@ -26,8 +31,13 @@ | |||
| 26 | 31 | {%elsif cppClassName == 'Wrapper'%} | |
| 27 | 32 | ||
| 28 | 33 | String::Utf8Value {{ name }}(info[{{ jsArg }}]->ToString()); | |
| 34 | + // malloc with one extra byte so we can add the terminating null character C-strings expect: | ||
| 29 | 35 | from_{{ name }} = ({{ cType }}) malloc({{ name }}.length() + 1); | |
| 36 | + // copy the characters from the nodejs string into our C-string (used instead of strdup or strcpy because nulls in | ||
| 37 | + // the middle of strings are valid coming from nodejs): | ||
| 30 | 38 | memcpy((void *)from_{{ name }}, *{{ name }}, {{ name }}.length()); | |
| 39 | + // ensure the final byte of our new string is null, extra casts added to ensure compatibility with various C types | ||
| 40 | + // used in the nodejs binding generation: | ||
| 31 | 41 | memset((void *)(((char *)from_{{ name }}) + {{ name }}.length()), 0, 1); | |
| 32 | 42 | {%elsif cppClassName == 'Array'%} | |
| 33 | 43 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments