Skip to content

Commit

Permalink
fixing issue with comparison on some platforms (MIPS) (#55)
Browse files Browse the repository at this point in the history
* fixing issue with comparison on some platforms (MIPS), as unsigned arithmetic seems to be the default

Co-authored-by: Pat Buah <[email protected]>
  • Loading branch information
keldonin and EditUndo authored Feb 17, 2024
1 parent 515eb1c commit 7d41876
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/pkcs11_mechanism.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,16 @@ static int compare_CKM_type( const void *a, const void *b)
{
/* because we are making a comparison between unsigned long, int might not reflect well */
/* we need to use an intermediary value and divide it by itself (as absolute value) */

long long item = ((MechanismDesc *)a)->type - ((MechanismDesc *)b)->type;

/* we explicitely use "signed" as some platform (MIPS) seem to work with unsigned by default */
//avoiding undefined behaviour
MechanismDesc* mech_a = (MechanismDesc*)a;
MechanismDesc* mech_b = (MechanismDesc*)b;
if(!mech_a || !mech_b) {
fprintf(stderr, "***Error: failed to detect valid mechanism description...exiting.\n");
exit(rc_error_invalid_argument);
}
signed long long item = (signed long long)(mech_a->type) - (signed long long)(mech_b->type);
return item ? item/llabs(item) : 0;
}

Expand Down

0 comments on commit 7d41876

Please sign in to comment.