Skip to content

Commit c8de512

Browse files
committed
update aws_policy_equal.c
1 parent eda566f commit c8de512

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/aws_policy_equal/aws_policy_equal.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@
2626
** This function is part of the StackQL extension suite for SQLite, providing AWS policy comparison capabilities.
2727
*/
2828

29+
#include <math.h>
30+
#include <float.h>
31+
#include <string.h>
32+
#include <ctype.h>
33+
2934
#include <sqlite3ext.h>
3035
SQLITE_EXTENSION_INIT1
3136

3237
#include "cJSON.h"
33-
#include <string.h>
34-
#include <ctype.h>
3538

3639
// List of fields that should be compared as unordered sets
3740
static const char *unordered_arrays[] = {
@@ -71,7 +74,7 @@ static int aws_service_compare(const char *str1, const char *str2) {
7174
}
7275

7376
// Find an element in an array by value (for unordered comparison)
74-
static cJSON *find_matching_element(cJSON *array, cJSON *item, int parent_is_unordered) {
77+
static cJSON *find_matching_element(const cJSON *array, const cJSON *item, int parent_is_unordered) {
7578
cJSON *element;
7679

7780
// Nothing to find in empty arrays
@@ -208,8 +211,16 @@ static cJSON_bool aws_policy_compare_items(const cJSON *a, const cJSON *b, int p
208211
}
209212
}
210213

211-
// Forward declaration
214+
// Forward declarations
212215
static cJSON_bool aws_policy_compare_items(const cJSON *a, const cJSON *b, int parent_is_unordered);
216+
static cJSON *find_matching_element(const cJSON *array, const cJSON *item, int parent_is_unordered);
217+
static cJSON_bool compare_double(double a, double b);
218+
219+
// Compare doubles with appropriate epsilon
220+
static cJSON_bool compare_double(double a, double b) {
221+
double maxVal = fabs(a) > fabs(b) ? fabs(a) : fabs(b);
222+
return (fabs(a - b) <= maxVal * DBL_EPSILON);
223+
}
213224

214225
static void aws_policy_equal(sqlite3_context *context, int argc, sqlite3_value **argv) {
215226
if (argc != 2) {

0 commit comments

Comments
 (0)