-
Notifications
You must be signed in to change notification settings - Fork 1
fix: handle buffer size for wchars #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request fixes buffer size handling for wide characters (wchar_t) on Windows. The underlying licensing API expects character counts rather than byte counts, and on Windows, each wide character is 2 bytes, requiring proper conversion.
Key Changes:
- Added
getCharCount()helper function in C++ to convert byte lengths to character counts, with validation for UTF-16 alignment on Windows - Added
getCArray()helper function in TypeScript to create appropriately-sized buffers (2x size on Windows for wchar_t) - Updated all 13 affected native function bindings to use the new conversion logic
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 13 comments.
| File | Description |
|---|---|
| src/native/main.cpp | Added getCharCount() function and updated 13 functions to properly convert byte lengths to character counts for buffer operations |
| src/lexfloatclient.ts | Updated all buffer allocations to use getCArray() helper instead of direct Uint8Array construction |
| src/lexfloatclient-native.ts | Added getCArray() helper function to allocate platform-appropriate buffer sizes (2x on Windows) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Napi::Uint8Array array = info[0].As<Napi::Uint8Array>(); | ||
| size_t length = array.ElementLength(); | ||
| size_t length = getCharCount(env, array.ByteLength()); | ||
| if(env.IsExceptionPending()) { |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The opening brace style is inconsistent with the rest of the codebase. The established convention in this file is to place opening braces on a new line for if statements. Consider changing to match the existing style for consistency.
| Napi::Uint8Array array = info[0].As<Napi::Uint8Array>(); | ||
| size_t length = array.ElementLength(); | ||
| size_t length = getCharCount(env, array.ByteLength()); | ||
| if(env.IsExceptionPending()) { |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The opening brace style is inconsistent with the rest of the codebase. The established convention in this file is to place opening braces on a new line for if statements. Consider changing to match the existing style for consistency.
| Napi::Uint8Array array = info[1].As<Napi::Uint8Array>(); | ||
| size_t length = array.ElementLength(); | ||
| size_t length = getCharCount(env, array.ByteLength()); | ||
| if(env.IsExceptionPending()) { |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The opening brace style is inconsistent with the rest of the codebase. The established convention in this file is to place opening braces on a new line for if statements. Consider changing to match the existing style for consistency.
| Napi::Uint8Array array = info[0].As<Napi::Uint8Array>(); | ||
| size_t length = array.ElementLength(); | ||
| size_t length = getCharCount(env, array.ByteLength()); | ||
| if(env.IsExceptionPending()) { |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The opening brace style is inconsistent with the rest of the codebase. The established convention in this file is to place opening braces on a new line for if statements. Consider changing to match the existing style for consistency.
| CHARTYPE *arg2 = reinterpret_cast<CHARTYPE *>(array2.ArrayBuffer().Data()); | ||
| size_t length = array2.ElementLength(); | ||
| size_t length = getCharCount(env, array2.ByteLength()); | ||
| if(env.IsExceptionPending()) { |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The opening brace style is inconsistent with the rest of the codebase. The established convention in this file is to place opening braces on a new line for if statements. Consider changing to match the existing style for consistency.
| Napi::Uint8Array array = info[1].As<Napi::Uint8Array>(); | ||
| size_t length = array.ElementLength(); | ||
| size_t length = getCharCount(env, array.ByteLength()); | ||
| if(env.IsExceptionPending()) { |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The opening brace style is inconsistent with the rest of the codebase. The established convention in this file is to place opening braces on a new line for if statements. Consider changing to match the existing style for consistency.
| Napi::Uint8Array array = info[0].As<Napi::Uint8Array>(); | ||
| size_t length = array.ElementLength(); | ||
| size_t length = getCharCount(env, array.ByteLength()); | ||
| if(env.IsExceptionPending()) { |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The opening brace style is inconsistent with the rest of the codebase. The established convention in this file is to place opening braces on a new line for if statements. Consider changing to match the existing style for consistency.
| Napi::Uint8Array array = info[0].As<Napi::Uint8Array>(); | ||
| size_t length = array.ElementLength(); | ||
| size_t length = getCharCount(env, array.ByteLength()); | ||
| if(env.IsExceptionPending()) { |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The opening brace style is inconsistent with the rest of the codebase. The established convention in this file is to place opening braces on a new line for if statements. Consider changing to match the existing style for consistency.
| Napi::Uint8Array array = info[0].As<Napi::Uint8Array>(); | ||
| size_t length = array.ElementLength(); | ||
| size_t length = getCharCount(env, array.ByteLength()); | ||
| if(env.IsExceptionPending()) { |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The opening brace style is inconsistent with the rest of the codebase. The established convention in this file is to place opening braces on a new line for if statements, as seen in other functions (e.g., lines 72-75, 77-80, 112-115). Consider changing to match the existing style for consistency.
| Napi::Uint8Array array = info[0].As<Napi::Uint8Array>(); | ||
| size_t length = array.ElementLength(); | ||
| size_t length = getCharCount(env, array.ByteLength()); | ||
| if(env.IsExceptionPending()) { |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The opening brace style is inconsistent with the rest of the codebase. The established convention in this file is to place opening braces on a new line for if statements. Consider changing to match the existing style for consistency.


No description provided.