|
26 | 26 | ** This function is part of the StackQL extension suite for SQLite, providing AWS policy comparison capabilities.
|
27 | 27 | */
|
28 | 28 |
|
| 29 | +#include <math.h> |
| 30 | +#include <float.h> |
| 31 | +#include <string.h> |
| 32 | +#include <ctype.h> |
| 33 | + |
29 | 34 | #include <sqlite3ext.h>
|
30 | 35 | SQLITE_EXTENSION_INIT1
|
31 | 36 |
|
32 | 37 | #include "cJSON.h"
|
33 |
| -#include <string.h> |
34 |
| -#include <ctype.h> |
35 | 38 |
|
36 | 39 | // List of fields that should be compared as unordered sets
|
37 | 40 | static const char *unordered_arrays[] = {
|
@@ -71,7 +74,7 @@ static int aws_service_compare(const char *str1, const char *str2) {
|
71 | 74 | }
|
72 | 75 |
|
73 | 76 | // 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) { |
75 | 78 | cJSON *element;
|
76 | 79 |
|
77 | 80 | // 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
|
208 | 211 | }
|
209 | 212 | }
|
210 | 213 |
|
211 |
| -// Forward declaration |
| 214 | +// Forward declarations |
212 | 215 | 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 | +} |
213 | 224 |
|
214 | 225 | static void aws_policy_equal(sqlite3_context *context, int argc, sqlite3_value **argv) {
|
215 | 226 | if (argc != 2) {
|
|
0 commit comments