diff options
| -rw-r--r-- | src/plist.c | 78 | ||||
| -rw-r--r-- | src/time64.c | 26 | ||||
| -rw-r--r-- | test/plist_cmp.c | 4 | ||||
| -rw-r--r-- | test/plist_test.c | 12 |
4 files changed, 55 insertions, 65 deletions
diff --git a/src/plist.c b/src/plist.c index 57f0be4..4d327e0 100644 --- a/src/plist.c +++ b/src/plist.c | |||
| @@ -516,12 +516,11 @@ PLIST_API void plist_array_set_item(plist_t node, plist_t item, uint32_t n) | |||
| 516 | assert(idx >= 0); | 516 | assert(idx >= 0); |
| 517 | if (idx < 0) { | 517 | if (idx < 0) { |
| 518 | return; | 518 | return; |
| 519 | } else { | 519 | } |
| 520 | node_insert(node, idx, item); | 520 | node_insert(node, idx, item); |
| 521 | ptrarray_t* pa = ((plist_data_t)((node_t*)node)->data)->hashtable; | 521 | ptrarray_t* pa = ((plist_data_t)((node_t*)node)->data)->hashtable; |
| 522 | if (pa) { | 522 | if (pa) { |
| 523 | ptr_array_set(pa, item, idx); | 523 | ptr_array_set(pa, item, idx); |
| 524 | } | ||
| 525 | } | 524 | } |
| 526 | } | 525 | } |
| 527 | } | 526 | } |
| @@ -714,9 +713,8 @@ PLIST_API void plist_dict_set_item(plist_t node, const char* key, plist_t item) | |||
| 714 | assert(idx >= 0); | 713 | assert(idx >= 0); |
| 715 | if (idx < 0) { | 714 | if (idx < 0) { |
| 716 | return; | 715 | return; |
| 717 | } else { | ||
| 718 | node_insert(node, idx, item); | ||
| 719 | } | 716 | } |
| 717 | node_insert(node, idx, item); | ||
| 720 | key_node = node_prev_sibling(item); | 718 | key_node = node_prev_sibling(item); |
| 721 | } else { | 719 | } else { |
| 722 | key_node = plist_new_key(key); | 720 | key_node = plist_new_key(key); |
| @@ -1038,33 +1036,22 @@ int plist_data_compare(const void *a, const void *b) | |||
| 1038 | case PLIST_UID: | 1036 | case PLIST_UID: |
| 1039 | if (val_a->length != val_b->length) | 1037 | if (val_a->length != val_b->length) |
| 1040 | return FALSE; | 1038 | return FALSE; |
| 1041 | if (val_a->intval == val_b->intval) //it is an union so this is sufficient | 1039 | return val_a->intval == val_b->intval; //it is an union so this is sufficient |
| 1042 | return TRUE; | ||
| 1043 | else | ||
| 1044 | return FALSE; | ||
| 1045 | 1040 | ||
| 1046 | case PLIST_KEY: | 1041 | case PLIST_KEY: |
| 1047 | case PLIST_STRING: | 1042 | case PLIST_STRING: |
| 1048 | if (!strcmp(val_a->strval, val_b->strval)) | 1043 | return strcmp(val_a->strval, val_b->strval) == 0; |
| 1049 | return TRUE; | ||
| 1050 | else | ||
| 1051 | return FALSE; | ||
| 1052 | 1044 | ||
| 1053 | case PLIST_DATA: | 1045 | case PLIST_DATA: |
| 1054 | if (val_a->length != val_b->length) | 1046 | if (val_a->length != val_b->length) |
| 1055 | return FALSE; | 1047 | return FALSE; |
| 1056 | if (!memcmp(val_a->buff, val_b->buff, val_a->length)) | 1048 | return memcmp(val_a->buff, val_b->buff, val_a->length) == 0; |
| 1057 | return TRUE; | 1049 | |
| 1058 | else | ||
| 1059 | return FALSE; | ||
| 1060 | case PLIST_ARRAY: | 1050 | case PLIST_ARRAY: |
| 1061 | case PLIST_DICT: | 1051 | case PLIST_DICT: |
| 1062 | //compare pointer | 1052 | //compare pointer |
| 1063 | if (a == b) | 1053 | return a == b; |
| 1064 | return TRUE; | 1054 | |
| 1065 | else | ||
| 1066 | return FALSE; | ||
| 1067 | break; | ||
| 1068 | default: | 1055 | default: |
| 1069 | break; | 1056 | break; |
| 1070 | } | 1057 | } |
| @@ -1195,11 +1182,13 @@ PLIST_API int plist_uint_val_compare(plist_t uintnode, uint64_t cmpval) | |||
| 1195 | plist_get_uint_val(uintnode, &uintval); | 1182 | plist_get_uint_val(uintnode, &uintval); |
| 1196 | if (uintval == cmpval) { | 1183 | if (uintval == cmpval) { |
| 1197 | return 0; | 1184 | return 0; |
| 1198 | } else if (uintval < cmpval) { | 1185 | } |
| 1186 | |||
| 1187 | if (uintval < cmpval) { | ||
| 1199 | return -1; | 1188 | return -1; |
| 1200 | } else { | ||
| 1201 | return 1; | ||
| 1202 | } | 1189 | } |
| 1190 | |||
| 1191 | return 1; | ||
| 1203 | } | 1192 | } |
| 1204 | 1193 | ||
| 1205 | PLIST_API int plist_uid_val_compare(plist_t uidnode, uint64_t cmpval) | 1194 | PLIST_API int plist_uid_val_compare(plist_t uidnode, uint64_t cmpval) |
| @@ -1211,11 +1200,13 @@ PLIST_API int plist_uid_val_compare(plist_t uidnode, uint64_t cmpval) | |||
| 1211 | plist_get_uid_val(uidnode, &uidval); | 1200 | plist_get_uid_val(uidnode, &uidval); |
| 1212 | if (uidval == cmpval) { | 1201 | if (uidval == cmpval) { |
| 1213 | return 0; | 1202 | return 0; |
| 1214 | } else if (uidval < cmpval) { | 1203 | } |
| 1204 | |||
| 1205 | if (uidval < cmpval) { | ||
| 1215 | return -1; | 1206 | return -1; |
| 1216 | } else { | ||
| 1217 | return 1; | ||
| 1218 | } | 1207 | } |
| 1208 | |||
| 1209 | return 1; | ||
| 1219 | } | 1210 | } |
| 1220 | 1211 | ||
| 1221 | PLIST_API int plist_real_val_compare(plist_t realnode, double cmpval) | 1212 | PLIST_API int plist_real_val_compare(plist_t realnode, double cmpval) |
| @@ -1231,16 +1222,22 @@ PLIST_API int plist_real_val_compare(plist_t realnode, double cmpval) | |||
| 1231 | double diff = fabs(a - b); | 1222 | double diff = fabs(a - b); |
| 1232 | if (a == b) { | 1223 | if (a == b) { |
| 1233 | return 0; | 1224 | return 0; |
| 1234 | } else if (a == 0 || b == 0 || (abs_a + abs_b < DBL_MIN)) { | 1225 | } |
| 1226 | |||
| 1227 | if (a == 0 || b == 0 || (abs_a + abs_b < DBL_MIN)) { | ||
| 1235 | if (diff < (DBL_EPSILON * DBL_MIN)) { | 1228 | if (diff < (DBL_EPSILON * DBL_MIN)) { |
| 1236 | return 0; | 1229 | return 0; |
| 1237 | } else if (a < b) { | 1230 | } |
| 1231 | |||
| 1232 | if (a < b) { | ||
| 1238 | return -1; | 1233 | return -1; |
| 1239 | } | 1234 | } |
| 1240 | } else { | 1235 | } else { |
| 1241 | if ((diff / fmin(abs_a + abs_b, DBL_MAX)) < DBL_EPSILON) { | 1236 | if ((diff / fmin(abs_a + abs_b, DBL_MAX)) < DBL_EPSILON) { |
| 1242 | return 0; | 1237 | return 0; |
| 1243 | } else if (a < b) { | 1238 | } |
| 1239 | |||
| 1240 | if (a < b) { | ||
| 1244 | return -1; | 1241 | return -1; |
| 1245 | } | 1242 | } |
| 1246 | } | 1243 | } |
| @@ -1259,11 +1256,13 @@ PLIST_API int plist_date_val_compare(plist_t datenode, int32_t cmpsec, int32_t c | |||
| 1259 | uint64_t cmpval = ((int64_t)cmpsec << 32) | cmpusec; | 1256 | uint64_t cmpval = ((int64_t)cmpsec << 32) | cmpusec; |
| 1260 | if (dateval == cmpval) { | 1257 | if (dateval == cmpval) { |
| 1261 | return 0; | 1258 | return 0; |
| 1262 | } else if (dateval < cmpval) { | 1259 | } |
| 1260 | |||
| 1261 | if (dateval < cmpval) { | ||
| 1263 | return -1; | 1262 | return -1; |
| 1264 | } else { | ||
| 1265 | return 1; | ||
| 1266 | } | 1263 | } |
| 1264 | |||
| 1265 | return 1; | ||
| 1267 | } | 1266 | } |
| 1268 | 1267 | ||
| 1269 | PLIST_API int plist_string_val_compare(plist_t strnode, const char* cmpval) | 1268 | PLIST_API int plist_string_val_compare(plist_t strnode, const char* cmpval) |
| @@ -1328,9 +1327,12 @@ PLIST_API int plist_data_val_compare(plist_t datanode, const uint8_t* cmpval, si | |||
| 1328 | plist_data_t data = plist_get_data(datanode); | 1327 | plist_data_t data = plist_get_data(datanode); |
| 1329 | if (data->length < n) { | 1328 | if (data->length < n) { |
| 1330 | return -1; | 1329 | return -1; |
| 1331 | } else if (data->length > n) { | 1330 | } |
| 1331 | |||
| 1332 | if (data->length > n) { | ||
| 1332 | return 1; | 1333 | return 1; |
| 1333 | } | 1334 | } |
| 1335 | |||
| 1334 | return memcmp(data->buff, cmpval, n); | 1336 | return memcmp(data->buff, cmpval, n); |
| 1335 | } | 1337 | } |
| 1336 | 1338 | ||
diff --git a/src/time64.c b/src/time64.c index db571d8..364e159 100644 --- a/src/time64.c +++ b/src/time64.c | |||
| @@ -176,34 +176,28 @@ static int is_exception_century(Year year) | |||
| 176 | static int cmp_date( const struct TM* left, const struct tm* right ) { | 176 | static int cmp_date( const struct TM* left, const struct tm* right ) { |
| 177 | if( left->tm_year > right->tm_year ) | 177 | if( left->tm_year > right->tm_year ) |
| 178 | return 1; | 178 | return 1; |
| 179 | else if( left->tm_year < right->tm_year ) | 179 | if( left->tm_year < right->tm_year ) |
| 180 | return -1; | 180 | return -1; |
| 181 | |||
| 182 | if( left->tm_mon > right->tm_mon ) | 181 | if( left->tm_mon > right->tm_mon ) |
| 183 | return 1; | 182 | return 1; |
| 184 | else if( left->tm_mon < right->tm_mon ) | 183 | if( left->tm_mon < right->tm_mon ) |
| 185 | return -1; | 184 | return -1; |
| 186 | |||
| 187 | if( left->tm_mday > right->tm_mday ) | 185 | if( left->tm_mday > right->tm_mday ) |
| 188 | return 1; | 186 | return 1; |
| 189 | else if( left->tm_mday < right->tm_mday ) | 187 | if( left->tm_mday < right->tm_mday ) |
| 190 | return -1; | 188 | return -1; |
| 191 | |||
| 192 | if( left->tm_hour > right->tm_hour ) | 189 | if( left->tm_hour > right->tm_hour ) |
| 193 | return 1; | 190 | return 1; |
| 194 | else if( left->tm_hour < right->tm_hour ) | 191 | if( left->tm_hour < right->tm_hour ) |
| 195 | return -1; | 192 | return -1; |
| 196 | |||
| 197 | if( left->tm_min > right->tm_min ) | 193 | if( left->tm_min > right->tm_min ) |
| 198 | return 1; | 194 | return 1; |
| 199 | else if( left->tm_min < right->tm_min ) | 195 | if( left->tm_min < right->tm_min ) |
| 200 | return -1; | 196 | return -1; |
| 201 | |||
| 202 | if( left->tm_sec > right->tm_sec ) | 197 | if( left->tm_sec > right->tm_sec ) |
| 203 | return 1; | 198 | return 1; |
| 204 | else if( left->tm_sec < right->tm_sec ) | 199 | if( left->tm_sec < right->tm_sec ) |
| 205 | return -1; | 200 | return -1; |
| 206 | |||
| 207 | return 0; | 201 | return 0; |
| 208 | } | 202 | } |
| 209 | 203 | ||
| @@ -774,15 +768,15 @@ struct TM *localtime64_r (const Time64_T *timev, struct TM *local_tm) | |||
| 774 | static int valid_tm_wday( const struct TM* date ) { | 768 | static int valid_tm_wday( const struct TM* date ) { |
| 775 | if( 0 <= date->tm_wday && date->tm_wday <= 6 ) | 769 | if( 0 <= date->tm_wday && date->tm_wday <= 6 ) |
| 776 | return 1; | 770 | return 1; |
| 777 | else | 771 | |
| 778 | return 0; | 772 | return 0; |
| 779 | } | 773 | } |
| 780 | 774 | ||
| 781 | static int valid_tm_mon( const struct TM* date ) { | 775 | static int valid_tm_mon( const struct TM* date ) { |
| 782 | if( 0 <= date->tm_mon && date->tm_mon <= 11 ) | 776 | if( 0 <= date->tm_mon && date->tm_mon <= 11 ) |
| 783 | return 1; | 777 | return 1; |
| 784 | else | 778 | |
| 785 | return 0; | 779 | return 0; |
| 786 | } | 780 | } |
| 787 | 781 | ||
| 788 | 782 | ||
diff --git a/test/plist_cmp.c b/test/plist_cmp.c index a07452b..c854446 100644 --- a/test/plist_cmp.c +++ b/test/plist_cmp.c | |||
| @@ -139,12 +139,10 @@ int main(int argc, char *argv[]) | |||
| 139 | printf("PList parsing failed\n"); | 139 | printf("PList parsing failed\n"); |
| 140 | return 3; | 140 | return 3; |
| 141 | } | 141 | } |
| 142 | else | ||
| 143 | printf("PList parsing succeeded\n"); | ||
| 144 | 142 | ||
| 143 | printf("PList parsing succeeded\n"); | ||
| 145 | res = compare_plist(root_node1, root_node2); | 144 | res = compare_plist(root_node1, root_node2); |
| 146 | 145 | ||
| 147 | |||
| 148 | plist_free(root_node1); | 146 | plist_free(root_node1); |
| 149 | plist_free(root_node2); | 147 | plist_free(root_node2); |
| 150 | 148 | ||
diff --git a/test/plist_test.c b/test/plist_test.c index b498e1d..6e3947a 100644 --- a/test/plist_test.c +++ b/test/plist_test.c | |||
| @@ -77,36 +77,32 @@ int main(int argc, char *argv[]) | |||
| 77 | printf("PList XML parsing failed\n"); | 77 | printf("PList XML parsing failed\n"); |
| 78 | return 3; | 78 | return 3; |
| 79 | } | 79 | } |
| 80 | else | ||
| 81 | printf("PList XML parsing succeeded\n"); | ||
| 82 | 80 | ||
| 81 | printf("PList XML parsing succeeded\n"); | ||
| 83 | plist_to_bin(root_node1, &plist_bin, &size_out); | 82 | plist_to_bin(root_node1, &plist_bin, &size_out); |
| 84 | if (!plist_bin) | 83 | if (!plist_bin) |
| 85 | { | 84 | { |
| 86 | printf("PList BIN writing failed\n"); | 85 | printf("PList BIN writing failed\n"); |
| 87 | return 4; | 86 | return 4; |
| 88 | } | 87 | } |
| 89 | else | ||
| 90 | printf("PList BIN writing succeeded\n"); | ||
| 91 | 88 | ||
| 89 | printf("PList BIN writing succeeded\n"); | ||
| 92 | plist_from_bin(plist_bin, size_out, &root_node2); | 90 | plist_from_bin(plist_bin, size_out, &root_node2); |
| 93 | if (!root_node2) | 91 | if (!root_node2) |
| 94 | { | 92 | { |
| 95 | printf("PList BIN parsing failed\n"); | 93 | printf("PList BIN parsing failed\n"); |
| 96 | return 5; | 94 | return 5; |
| 97 | } | 95 | } |
| 98 | else | ||
| 99 | printf("PList BIN parsing succeeded\n"); | ||
| 100 | 96 | ||
| 97 | printf("PList BIN parsing succeeded\n"); | ||
| 101 | plist_to_xml(root_node2, &plist_xml2, &size_out2); | 98 | plist_to_xml(root_node2, &plist_xml2, &size_out2); |
| 102 | if (!plist_xml2) | 99 | if (!plist_xml2) |
| 103 | { | 100 | { |
| 104 | printf("PList XML writing failed\n"); | 101 | printf("PList XML writing failed\n"); |
| 105 | return 8; | 102 | return 8; |
| 106 | } | 103 | } |
| 107 | else | ||
| 108 | printf("PList XML writing succeeded\n"); | ||
| 109 | 104 | ||
| 105 | printf("PList XML writing succeeded\n"); | ||
| 110 | if (plist_xml2) | 106 | if (plist_xml2) |
| 111 | { | 107 | { |
| 112 | FILE *oplist = NULL; | 108 | FILE *oplist = NULL; |
