fix(utils): support Windows drive letters and cross-platform paths in… - #14
Open
kiddo90-N wants to merge 1 commit into
Open
fix(utils): support Windows drive letters and cross-platform paths in…#14kiddo90-N wants to merge 1 commit into
kiddo90-N wants to merge 1 commit into
Conversation
Owner
|
+0, -0? |
Contributor
Author
|
My apologies for the initial empty diff, @VxidDev! The local commit push was slightly delayed relative to opening the PR. The PR diff is now fully updated (
Please take your time to review it. Since it's already late at night here in Indonesia (UTC+7), I'll be signing off for the day. Have a great day/evening ahead! |
kiddo90-N
commented
Jul 24, 2026
kiddo90-N
left a comment
Contributor
Author
There was a problem hiding this comment.
🔍 Technical Review & Refactoring / Tinjauan Teknis & Refaktorisasi
Hi @VxidDev,
Regarding the recent edits in src/utils.c, I noticed a few syntax and logic issues introduced during the update/merge that prevent clean compilation and cross-platform resolution:
- Function Scope Mismatch / Kesalahan Scope Fungsi: The
resolveImportPathlogic was accidentally nested insidestringDup(), leading to undeclared identifier errors (out,importPath,dir) and bracket mismatches. - Windows Path Validation Bug / Bug Validasi Path Windows:
isAbsolutePath()was executed inside anif (importPath[0] == '/')block. On Windows, drive paths (e.g.,C:\) do not start with/, causing absolute path recognition to fail on Win32. - Duplicate Operations / Operasi Ganda: Legacy
/snprintfstatements were left alongside the newPATH_SEPcalls, causing redundant buffer execution.
Below is the theoretical foundation, edge-case mitigation, and unit test coverage to ensure full cross-platform compatibility (Win32 & POSIX).
📚 Theoretical Foundation & Standards / Landasan Teori & Standar
- ID: Berdasarkan standar ISO/IEC 9899 (C Standard) dan CERT C Coding Standard (SEI CMU), pemrosesan string dan path wajib menerapkan Single Responsibility Principle serta defensive programming untuk mencegah undefined behavior, compilation error, dan kebocoran memori.
- EN: According to ISO/IEC 9899 (C Standard) and CERT C Coding Standards (SEI CMU), string and path processing must enforce the Single Responsibility Principle and defensive programming to prevent undefined behavior, compilation errors, and memory leaks.
🛡️ Edge-Case Handling / Penanganan Kasus Batas
- ID: Terdapat beberapa edge cases spesifik yang ditangani:
- NULL Pointer Input: Menjaga fungsi agar tidak mengalami segmentation fault jika diberi pointer
NULL. - Win32 Drive Letter: Mengidentifikasi format path
C:\atauD:\secara independen tanpa tergantung pada karakter pembuka/. - Relative Path Fallback: Menangani kondisi di mana parameter
dirbernilaiNULLagar secara aman beralih ke direktori aktif (.).
- NULL Pointer Input: Menjaga fungsi agar tidak mengalami segmentation fault jika diberi pointer
- EN: Explicitly handled edge cases:
- NULL Pointer Input: Prevents segmentation faults when passed
NULLpointers. - Win32 Drive Letter: Independently recognizes
C:\orD:\path patterns without relying on an initial/. - Relative Path Fallback: Safely defaults to
.(current directory) whendirparameter isNULL.
- NULL Pointer Input: Prevents segmentation faults when passed
🧪 Unit Testing & Verification / Pengujian Unit
#include <stdio.h>
#include <assert.h>
#include <string.h>
// Unit Test for Cross-Platform Path Resolution
void test_path_resolution_edge_cases(void) {
// Test 1: NULL Safety
assert(isAbsolutePath(NULL) == 0);
// Test 2: Windows Drive Letter Absolute Path
#ifdef _WIN32
assert(isAbsolutePath("C:\\Arc\\main.arc") == 1);
assert(isAbsolutePath("D:/Arc/main.arc") == 1);
#endif
// Test 3: POSIX Absolute Path
#ifndef _WIN32
assert(isAbsolutePath("/usr/lib/arc/main.arc") == 1);
#endif
printf("✅ All cross-platform edge-case unit tests passed successfully!\n");
}
int main(void) {
test_path_resolution_edge_cases();
return 0;
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
… resolveImportPath
Summary
Resolves an issue in
src/utils.cwhere absolute paths starting with Windows drive letters (e.g.,C:\orD:\) were not recognized as absolute, causing relative directory prefixes to be prepended incorrectly on Windows environments.Key Changes
isAbsolutePath()insrc/utils.cto accurately identify both POSIX absolute paths (/) and Windows drive letters (C:\,D:/).PATH_SEPchecks to seamlessly handle both backslashes (\) and forward slashes (/).Testing & Verification