Skip to content

fix(core): resolve C pointer qualifier errors and implement BLI_strncpy_wchar_from_utf8 - #77

Merged
ppmpreetham merged 1 commit into
ppmpreetham:mainfrom
mlubbad:fix/core-c-pointer-qualifiers-and-utf8-strncpy
Nov 27, 2026
Merged

ppmpreetham merged 1 commit into
ppmpreetham:mainfrom
mlubbad:fix/core-c-pointer-qualifiers-and-utf8-strncpy

Conversation

@mlubbad

@mlubbad mlubbad commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

What does this change?

Fixes four strict C11/Clang compilation bugs in core/:

  1. core/intern/string_utf8.c (BLI_strncpy_wchar_from_utf8): After the WIN32 utfconv branch was removed, BLI_strncpy_wchar_from_utf8 was left with an empty body and no return statement (-Wreturn-type undefined behavior). Implemented safe UTF-8 decoding into dst_w via BLI_str_utf8_as_unicode_step_safe with NUL termination.
  2. core/intern/math_geom.c (isect_seg_seg_v2_point_ex): BUI_SWAP(v0, v2) on const float v0[2] expands typeof(v0) to const float * in Clang/GCC, causing assignment to a const-qualified temporary to fail under strict C flags; replaced with an explicit const float *v_tmp pointer swap.
  3. core/include/BLI_endian_switch_inline.h: Added explicit (unsigned int *) cast in BLI_endian_switch_int32 (-Wpointer-sign).
  4. core/intern/BLI_ghash_utils.c: Passed ptr directly to MEM_freeN(ptr) without casting to const GHashPair * (-Wdiscarded-qualifiers).

How was it tested?

  • Verified Clang syntax/qualifier checks (clang -fsyntax-only) on modified core/ translation units.

Checklist

  • Existing SPDX headers preserved

Summary by CodeRabbit

  • Bug Fixes
    • Improved UTF-8 to wide-character conversion so it respects destination capacity, preserves space for a terminating character, and handles empty destinations safely.
    • Corrected edge-case handling when calculating intersections between line segments, including cases where one segment is a point.
    • Made small reliability improvements to byte swapping and memory cleanup.

…py_wchar_from_utf8

- Cast int * to unsigned int * in BLI_endian_switch_int32 to prevent pointer sign mismatch warnings/errors.
- Drop const cast passed to MEM_freeN(void *) in BLI_ghashutil_pairfree.
- Swap const float * segment pointers explicitly in isect_seg_seg_v2_point_ex instead of BUI_SWAP, which fails when typeof preserves const on the temporary variable.
- Implement UTF-8 to wchar_t decoding loop in BLI_strncpy_wchar_from_utf8, which had an empty function body missing a return statement.

Signed-off-by: Dr. Mohammed Lubbad <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The changes update integer byte-swap casting, GHashPair freeing, segment endpoint exchange, and UTF-8-to-wide-character conversion.

Changes: Endian conversion

Layer / File(s) Summary
Update the int32 byte-swap call
core/include/BLI_endian_switch_inline.h
BLI_endian_switch_int32 now casts its argument to unsigned int * when calling BLI_endian_switch_uint32.

GHashPair freeing

Layer / File(s) Summary
Pass the pointer directly to MEM_freeN
core/intern/BLI_ghash_utils.c
BLI_ghashutil_pairfree now passes ptr directly to MEM_freeN.

Segment intersection

Layer / File(s) Summary
Exchange segment endpoint pointers
core/intern/math_geom.c
When the first segment is a point and the second is not, the function exchanges endpoint pointers through a temporary pointer before recalculating the segment vectors.

Wide string conversion

Layer / File(s) Summary
Convert UTF-8 with the safe step decoder
core/intern/string_utf8.c
BLI_strncpy_wchar_from_utf8 uses the safe step decoder. It returns zero when destination capacity is zero; otherwise, it converts within the source and destination limits, terminates the output, and returns the number of wide characters written.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: ppmpreetham

Merge Risk: Minimal · up to 91c9e

This PR fixes strict C11/Clang pointer-qualifier errors and implements UTF-8 to wide-character conversion in the core library. No concrete defect was found in the changes. The conversion function has no callers in the repository today, so its practical impact is small. The risk of merging is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the two main kinds of change in the PR: fixing C pointer qualifier errors in core/ and implementing BLI_strncpy_wchar_from_utf8. The raw summary confirms both: the BLI_strncpy_wchar_fr…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the two main kinds of change in the PR: fixing C pointer qualifier errors in core/ and implementing BLI_strncpy_wchar_from_utf8. The raw summary confirms both: the BLI_strncpy_wchar_from_utf8 rewrite and the pointer and cast fixes in the endian switch, ghash pairfree, and segment intersection code. The title is specific and matches the changeset. It is long at 87 characters, and it does not mention the segment-intersection change, but it still covers the primary change.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4bf3a61a-5424-4583-88ea-852eed7576fe
Commits

Reviewing files that changed from the base of the PR and between e240e9b and 91c9e50.

Files selected for processing: 4

  • core/include/BLI_endian_switch_inline.h
  • core/intern/BLI_ghash_utils.c
  • core/intern/math_geom.c
  • core/intern/string_utf8.c

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@ppmpreetham
ppmpreetham merged commit 1af5d50 into ppmpreetham:main Nov 27, 2026
1 check passed
@ppmpreetham

Copy link
Copy Markdown
Owner

Thank you very much for the PR!
Merged (:

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.

2 participants