Skip to content

Conversation

@mir-huzaif
Copy link
Contributor

No description provided.

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
60.9% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

Copy link

Copilot AI left a 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 PR fixes wide character (wchar) handling for cross-platform compatibility between Windows (UTF-16) and Unix-based systems (UTF-8). The fix addresses an issue where character buffer sizes were incorrectly calculated on Windows, which uses 2-byte UTF-16 encoding (wchar_t).

Key Changes:

  • Added platform-specific character count calculation in C++ to properly handle UTF-16 on Windows
  • Introduced a TypeScript helper function to allocate appropriately sized buffers based on platform encoding
  • Applied these changes consistently across 30+ API functions

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 26 comments.

File Description
src/native/main.cpp Added getCharCount() function to convert byte lengths to character counts (dividing by 2 on Windows for UTF-16), and updated all buffer length calculations to use this function with proper error handling
src/lexactivator-native.ts Added getCArray() function to allocate buffers with correct byte sizes (doubled on Windows for UTF-16 encoding)
src/lexactivator.ts Replaced all direct Uint8Array instantiations with calls to getCArray() to ensure proper buffer allocation across platforms

💡 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()) {
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space between 'if' and '(' to match the existing code style in this file. The existing code consistently uses 'if (condition)' with a space.

Suggested change
if(env.IsExceptionPending()) {
if (env.IsExceptionPending()) {

Copilot uses AI. Check for mistakes.
Napi::Uint8Array array = info[0].As<Napi::Uint8Array>();
size_t length = array.ElementLength();
size_t length = getCharCount(env, array.ByteLength());
if(env.IsExceptionPending()) {
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space between 'if' and '(' to match the existing code style in this file. The existing code consistently uses 'if (condition)' with a space.

Copilot uses AI. Check for mistakes.
Napi::Uint8Array array = info[1].As<Napi::Uint8Array>();
size_t length = array.ElementLength();
size_t length = getCharCount(env, array.ByteLength());
if(env.IsExceptionPending()) {
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space between 'if' and '(' to match the existing code style in this file. The existing code consistently uses 'if (condition)' with a space.

Copilot uses AI. Check for mistakes.
Napi::Uint8Array array = info[0].As<Napi::Uint8Array>();
size_t length = array.ElementLength();
size_t length = getCharCount(env, array.ByteLength());
if(env.IsExceptionPending()) {
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space between 'if' and '(' to match the existing code style in this file. The existing code consistently uses 'if (condition)' with a space.

Suggested change
if(env.IsExceptionPending()) {
if (env.IsExceptionPending()) {

Copilot uses AI. Check for mistakes.
Napi::Uint8Array array = info[0].As<Napi::Uint8Array>();
size_t length = array.ElementLength();
size_t length = getCharCount(env, array.ByteLength());
if(env.IsExceptionPending()) {
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space between 'if' and '(' to match the existing code style in this file. The existing code consistently uses 'if (condition)' with a space.

Copilot uses AI. Check for mistakes.
Napi::Uint8Array array = info[1].As<Napi::Uint8Array>();
size_t length = array.ElementLength();
size_t length = getCharCount(env, array.ByteLength());
if(env.IsExceptionPending()) {
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space between 'if' and '(' to match the existing code style in this file. The existing code consistently uses 'if (condition)' with a space.

Suggested change
if(env.IsExceptionPending()) {
if (env.IsExceptionPending()) {

Copilot uses AI. Check for mistakes.
Napi::Uint8Array array = info[0].As<Napi::Uint8Array>();
size_t length = array.ElementLength();
size_t length = getCharCount(env, array.ByteLength());
if(env.IsExceptionPending()) {
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space between 'if' and '(' to match the existing code style in this file. The existing code consistently uses 'if (condition)' with a space.

Copilot uses AI. Check for mistakes.
Napi::Uint8Array array = info[0].As<Napi::Uint8Array>();
size_t length = array.ElementLength();
size_t length = getCharCount(env, array.ByteLength());
if(env.IsExceptionPending()) {
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space between 'if' and '(' to match the existing code style in this file. The existing code consistently uses 'if (condition)' with a space.

Copilot uses AI. Check for mistakes.
Napi::Uint8Array array = info[0].As<Napi::Uint8Array>();
size_t length = array.ElementLength();
size_t length = getCharCount(env, array.ByteLength());
if(env.IsExceptionPending()) {
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space between 'if' and '(' to match the existing code style in this file. The existing code consistently uses 'if (condition)' with a space.

Copilot uses AI. Check for mistakes.
Napi::Uint8Array array = info[0].As<Napi::Uint8Array>();
size_t length = array.ElementLength();
size_t length = getCharCount(env, array.ByteLength());
if(env.IsExceptionPending()) {
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space between 'if' and '(' to match the existing code style in this file. The existing code consistently uses 'if (condition)' with a space.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants