Skip to content

Fixed compatibility check for versions connections#292

Merged
JohnAmadis merged 5 commits intodevelopfrom
feature/fix-compatibility-check
Mar 11, 2026
Merged

Fixed compatibility check for versions connections#292
JohnAmadis merged 5 commits intodevelopfrom
feature/fix-compatibility-check

Conversation

@JohnAmadis
Copy link
Contributor

This pull request refactors the API signature comparison logic throughout the codebase to use compatibility checks rather than strict equality. It introduces new helper functions for more granular version compatibility checks and updates all relevant usages and documentation accordingly.

API Signature Compatibility Refactor:

  • Replaces all usages and declarations of Dmod_ApiSignature_AreEqual with the new Dmod_ApiSignature_AreCompatible function, updating both header (dmod.h) and implementation files to reflect the new compatibility-based approach. [1] [2] [3] [4] [5] [6]

Granular Version Compatibility Checks:

  • Introduces new static helper functions: ApiSignature_AreApiVersionsCompatible, ApiSignature_AreModuleVersionsCompatible, and ApiSignature_AreVersionsCompatible to separately check API and module version compatibility, and uses these in the main compatibility logic. [1] [2]

Documentation and Logging Updates:

  • Updates function documentation and error messages to clarify that the checks are for compatibility, not equality, and improves log specificity for version mismatches. [1] [2]

Parsing Logic Adjustments:

  • Fixes the parsing delimiters in ApiSignature_AreNamesEqual and ApiSignature_AreModulesEqual to properly distinguish between name and module boundaries using @ and : respectively. [1] [2]

Internal Logic Improvements:

  • Refactors the main compatibility function to use the new granular version compatibility helpers, ensuring that both API and module versions are checked for compatibility rather than strict equality. [1] [2]

These changes improve the flexibility and correctness of API signature matching, allowing for more robust module interoperation.

@JohnAmadis JohnAmadis requested a review from Copilot March 11, 2026 08:00
@JohnAmadis JohnAmadis self-assigned this Mar 11, 2026
@JohnAmadis JohnAmadis added the bug Something isn't working label Mar 11, 2026
@JohnAmadis
Copy link
Contributor Author

@copilot dopisz unit testy do tej funkcjonalności - takie, które sprawdzą różne sygnatury i czy będą poprawnie podpięte czy nie. Prawdopodobnie te unit testy będą failować, bo z tego co widzę jest jakiś crash, więc wygląda na to, że jakiś błąd zrobiłem - spróbuj go naprawić

Copy link
Contributor

Copilot AI commented Mar 11, 2026

@JohnAmadis I've opened a new pull request, #293, to work on those changes. Once the pull request is ready, I'll request review from you.

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 refactors API signature matching across the DMOD system from strict equality to a compatibility-based comparison, updating call sites and introducing more granular helper checks in the common signature parsing logic.

Changes:

  • Replaces Dmod_ApiSignature_AreEqual with Dmod_ApiSignature_AreCompatible across system/public API connection and lookup paths.
  • Updates signature parsing boundaries for name/module comparisons (using @ for name end and : for module end).
  • Adds helper functions to separately evaluate API-version and module-version compatibility and uses them in the top-level compatibility check.

Reviewed changes

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

File Description
src/system/public/dmod_dmf_api.c Uses compatibility matching when connecting APIs and looking up functions/modules by signature.
src/system/dmod_system.c Updates DIF function lookup to use compatibility matching.
src/common/dmod_common.c Renames/rewires signature comparison to compatibility and adds granular version-compat helpers and delimiter fixes.
inc/dmod.h Exposes the new Dmod_ApiSignature_AreCompatible API.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +551 to +568
static bool ApiSignature_AreModuleVersionsCompatible( const char* Signature1, const char* Signature2 )
{
const char* moduleVersion1 = ApiSignature_GetModuleVersion( Signature1 );
const char* moduleVersion2 = ApiSignature_GetModuleVersion( Signature2 );

while( *moduleVersion1 != '\0' && *moduleVersion2 != '\0' && *moduleVersion1 != '.' && *moduleVersion2 != '.' )
{
if( *moduleVersion1 != *moduleVersion2 )
{
DMOD_LOG_ERROR("Module version mismatch: %s != %s\n", moduleVersion1, moduleVersion2);
return false;
}
moduleVersion1++;
moduleVersion2++;
}

return *moduleVersion1 == *moduleVersion2;
}
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

ApiSignature_AreModuleVersionsCompatible() dereferences moduleVersion1/moduleVersion2 without checking for NULL. ApiSignature_GetModuleVersion() returns NULL when the signature version has no '/' (e.g. signatures like "...:1.0" exist in the repo), which will crash when Dmod_ApiSignature_AreCompatible() is used (e.g. from Dmod_GetFunction). Handle missing module-version gracefully (e.g., treat "no module version" as compatible when both are missing, or skip module-version comparison when either side lacks it) before entering the loop.

Copilot uses AI. Check for mistakes.
@@ -355,7 +357,7 @@ bool Dmod_ApiSignature_AreEqual( const char* Signature1, const char* Signature2

Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

Dmod_ApiSignature_AreCompatible() only checks Dmod_ApiSignature_IsValid(), but IsValid() accepts signature types that don't include '@' / ':' (e.g. IRQ signatures). The helpers called here (ApiSignature_AreModulesEqual(), ApiSignature_AreApiVersionsCompatible()) assume those delimiters exist and can dereference NULL from strchr(), leading to a crash on valid inputs. Consider either tightening IsValid() for the signatures this function supports, or adding delimiter/prefix checks here and returning false (or falling back to strict string compare) when required fields are missing.

Suggested change
/*
* Some valid signature types (e.g. IRQ signatures) do not contain the
* '@' / ':' delimiters expected by the internal ApiSignature_* helpers.
* Only call those helpers when both signatures have the required
* delimiters; otherwise, fall back to strict string comparison to avoid
* dereferencing NULL pointers from strchr().
*/
const char* at1 = strchr( Signature1, '@' );
const char* colon1 = strchr( Signature1, ':' );
const char* at2 = strchr( Signature2, '@' );
const char* colon2 = strchr( Signature2, ':' );
bool hasStructured1 = ( at1 != NULL ) && ( colon1 != NULL ) && ( at1 < colon1 );
bool hasStructured2 = ( at2 != NULL ) && ( colon2 != NULL ) && ( at2 < colon2 );
if( !hasStructured1 || !hasStructured2 )
{
/* For non-structured signatures, treat compatibility as exact match. */
return strcmp( Signature1, Signature2 ) == 0;
}

Copilot uses AI. Check for mistakes.
Comment on lines +543 to +550
/**
* @brief Check if module versions are equal
*
* @param Signature1 First signature
* @param Signature2 Second signature
*
* @return true if module versions are compatible, false otherwise
*/
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

Docstring inconsistency: the @brief says "Check if module versions are equal" but the function name/return description are about compatibility. Update the brief to match the compatibility semantics to avoid misleading generated docs.

Copilot uses AI. Check for mistakes.
Copilot AI and others added 3 commits March 11, 2026 08:22
Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
… mixed length)

Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
Fix NULL dereference crashes in ApiSignature compatibility helpers and add unit tests
@JohnAmadis JohnAmadis merged commit a45efe5 into develop Mar 11, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants