Commit 9f60cdd7 authored by Rosen Penev's avatar Rosen Penev Committed by Nikias Bassen

Improve code readability by not using else after return

[clang-tidy] Found with readability-else-after-return
Signed-off-by: 's avatarRosen Penev <rosenp@gmail.com>
parent 2899553d
...@@ -516,12 +516,11 @@ PLIST_API void plist_array_set_item(plist_t node, plist_t item, uint32_t n) ...@@ -516,12 +516,11 @@ PLIST_API void plist_array_set_item(plist_t node, plist_t item, uint32_t n)
assert(idx >= 0); assert(idx >= 0);
if (idx < 0) { if (idx < 0) {
return; return;
} else { }
node_insert(node, idx, item); node_insert(node, idx, item);
ptrarray_t* pa = ((plist_data_t)((node_t*)node)->data)->hashtable; ptrarray_t* pa = ((plist_data_t)((node_t*)node)->data)->hashtable;
if (pa) { if (pa) {
ptr_array_set(pa, item, idx); ptr_array_set(pa, item, idx);
}
} }
} }
} }
...@@ -714,9 +713,8 @@ PLIST_API void plist_dict_set_item(plist_t node, const char* key, plist_t item) ...@@ -714,9 +713,8 @@ PLIST_API void plist_dict_set_item(plist_t node, const char* key, plist_t item)
assert(idx >= 0); assert(idx >= 0);
if (idx < 0) { if (idx < 0) {
return; return;
} else {
node_insert(node, idx, item);
} }
node_insert(node, idx, item);
key_node = node_prev_sibling(item); key_node = node_prev_sibling(item);
} else { } else {
key_node = plist_new_key(key); key_node = plist_new_key(key);
...@@ -1038,33 +1036,22 @@ int plist_data_compare(const void *a, const void *b) ...@@ -1038,33 +1036,22 @@ int plist_data_compare(const void *a, const void *b)
case PLIST_UID: case PLIST_UID:
if (val_a->length != val_b->length) if (val_a->length != val_b->length)
return FALSE; return FALSE;
if (val_a->intval == val_b->intval) //it is an union so this is sufficient return val_a->intval == val_b->intval; //it is an union so this is sufficient
return TRUE;
else
return FALSE;
case PLIST_KEY: case PLIST_KEY:
case PLIST_STRING: case PLIST_STRING:
if (!strcmp(val_a->strval, val_b->strval)) return strcmp(val_a->strval, val_b->strval) == 0;
return TRUE;
else
return FALSE;
case PLIST_DATA: case PLIST_DATA:
if (val_a->length != val_b->length) if (val_a->length != val_b->length)
return FALSE; return FALSE;
if (!memcmp(val_a->buff, val_b->buff, val_a->length)) return memcmp(val_a->buff, val_b->buff, val_a->length) == 0;
return TRUE;
else
return FALSE;
case PLIST_ARRAY: case PLIST_ARRAY:
case PLIST_DICT: case PLIST_DICT:
//compare pointer //compare pointer
if (a == b) return a == b;
return TRUE;
else
return FALSE;
break;
default: default:
break; break;
} }
...@@ -1195,11 +1182,13 @@ PLIST_API int plist_uint_val_compare(plist_t uintnode, uint64_t cmpval) ...@@ -1195,11 +1182,13 @@ PLIST_API int plist_uint_val_compare(plist_t uintnode, uint64_t cmpval)
plist_get_uint_val(uintnode, &uintval); plist_get_uint_val(uintnode, &uintval);
if (uintval == cmpval) { if (uintval == cmpval) {
return 0; return 0;
} else if (uintval < cmpval) { }
if (uintval < cmpval) {
return -1; return -1;
} else {
return 1;
} }
return 1;
} }
PLIST_API int plist_uid_val_compare(plist_t uidnode, uint64_t cmpval) 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,11 +1200,13 @@ PLIST_API int plist_uid_val_compare(plist_t uidnode, uint64_t cmpval)
plist_get_uid_val(uidnode, &uidval); plist_get_uid_val(uidnode, &uidval);
if (uidval == cmpval) { if (uidval == cmpval) {
return 0; return 0;
} else if (uidval < cmpval) { }
if (uidval < cmpval) {
return -1; return -1;
} else {
return 1;
} }
return 1;
} }
PLIST_API int plist_real_val_compare(plist_t realnode, double cmpval) 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,16 +1222,22 @@ PLIST_API int plist_real_val_compare(plist_t realnode, double cmpval)
double diff = fabs(a - b); double diff = fabs(a - b);
if (a == b) { if (a == b) {
return 0; return 0;
} else if (a == 0 || b == 0 || (abs_a + abs_b < DBL_MIN)) { }
if (a == 0 || b == 0 || (abs_a + abs_b < DBL_MIN)) {
if (diff < (DBL_EPSILON * DBL_MIN)) { if (diff < (DBL_EPSILON * DBL_MIN)) {
return 0; return 0;
} else if (a < b) { }
if (a < b) {
return -1; return -1;
} }
} else { } else {
if ((diff / fmin(abs_a + abs_b, DBL_MAX)) < DBL_EPSILON) { if ((diff / fmin(abs_a + abs_b, DBL_MAX)) < DBL_EPSILON) {
return 0; return 0;
} else if (a < b) { }
if (a < b) {
return -1; return -1;
} }
} }
...@@ -1259,11 +1256,13 @@ PLIST_API int plist_date_val_compare(plist_t datenode, int32_t cmpsec, int32_t c ...@@ -1259,11 +1256,13 @@ PLIST_API int plist_date_val_compare(plist_t datenode, int32_t cmpsec, int32_t c
uint64_t cmpval = ((int64_t)cmpsec << 32) | cmpusec; uint64_t cmpval = ((int64_t)cmpsec << 32) | cmpusec;
if (dateval == cmpval) { if (dateval == cmpval) {
return 0; return 0;
} else if (dateval < cmpval) { }
if (dateval < cmpval) {
return -1; return -1;
} else {
return 1;
} }
return 1;
} }
PLIST_API int plist_string_val_compare(plist_t strnode, const char* cmpval) 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,9 +1327,12 @@ PLIST_API int plist_data_val_compare(plist_t datanode, const uint8_t* cmpval, si
plist_data_t data = plist_get_data(datanode); plist_data_t data = plist_get_data(datanode);
if (data->length < n) { if (data->length < n) {
return -1; return -1;
} else if (data->length > n) { }
if (data->length > n) {
return 1; return 1;
} }
return memcmp(data->buff, cmpval, n); return memcmp(data->buff, cmpval, n);
} }
......
...@@ -176,34 +176,28 @@ static int is_exception_century(Year year) ...@@ -176,34 +176,28 @@ static int is_exception_century(Year year)
static int cmp_date( const struct TM* left, const struct tm* right ) { static int cmp_date( const struct TM* left, const struct tm* right ) {
if( left->tm_year > right->tm_year ) if( left->tm_year > right->tm_year )
return 1; return 1;
else if( left->tm_year < right->tm_year ) if( left->tm_year < right->tm_year )
return -1; return -1;
if( left->tm_mon > right->tm_mon ) if( left->tm_mon > right->tm_mon )
return 1; return 1;
else if( left->tm_mon < right->tm_mon ) if( left->tm_mon < right->tm_mon )
return -1; return -1;
if( left->tm_mday > right->tm_mday ) if( left->tm_mday > right->tm_mday )
return 1; return 1;
else if( left->tm_mday < right->tm_mday ) if( left->tm_mday < right->tm_mday )
return -1; return -1;
if( left->tm_hour > right->tm_hour ) if( left->tm_hour > right->tm_hour )
return 1; return 1;
else if( left->tm_hour < right->tm_hour ) if( left->tm_hour < right->tm_hour )
return -1; return -1;
if( left->tm_min > right->tm_min ) if( left->tm_min > right->tm_min )
return 1; return 1;
else if( left->tm_min < right->tm_min ) if( left->tm_min < right->tm_min )
return -1; return -1;
if( left->tm_sec > right->tm_sec ) if( left->tm_sec > right->tm_sec )
return 1; return 1;
else if( left->tm_sec < right->tm_sec ) if( left->tm_sec < right->tm_sec )
return -1; return -1;
return 0; return 0;
} }
...@@ -774,15 +768,15 @@ struct TM *localtime64_r (const Time64_T *timev, struct TM *local_tm) ...@@ -774,15 +768,15 @@ struct TM *localtime64_r (const Time64_T *timev, struct TM *local_tm)
static int valid_tm_wday( const struct TM* date ) { static int valid_tm_wday( const struct TM* date ) {
if( 0 <= date->tm_wday && date->tm_wday <= 6 ) if( 0 <= date->tm_wday && date->tm_wday <= 6 )
return 1; return 1;
else
return 0; return 0;
} }
static int valid_tm_mon( const struct TM* date ) { static int valid_tm_mon( const struct TM* date ) {
if( 0 <= date->tm_mon && date->tm_mon <= 11 ) if( 0 <= date->tm_mon && date->tm_mon <= 11 )
return 1; return 1;
else
return 0; return 0;
} }
......
...@@ -139,12 +139,10 @@ int main(int argc, char *argv[]) ...@@ -139,12 +139,10 @@ int main(int argc, char *argv[])
printf("PList parsing failed\n"); printf("PList parsing failed\n");
return 3; return 3;
} }
else
printf("PList parsing succeeded\n");
printf("PList parsing succeeded\n");
res = compare_plist(root_node1, root_node2); res = compare_plist(root_node1, root_node2);
plist_free(root_node1); plist_free(root_node1);
plist_free(root_node2); plist_free(root_node2);
......
...@@ -77,36 +77,32 @@ int main(int argc, char *argv[]) ...@@ -77,36 +77,32 @@ int main(int argc, char *argv[])
printf("PList XML parsing failed\n"); printf("PList XML parsing failed\n");
return 3; return 3;
} }
else
printf("PList XML parsing succeeded\n");
printf("PList XML parsing succeeded\n");
plist_to_bin(root_node1, &plist_bin, &size_out); plist_to_bin(root_node1, &plist_bin, &size_out);
if (!plist_bin) if (!plist_bin)
{ {
printf("PList BIN writing failed\n"); printf("PList BIN writing failed\n");
return 4; return 4;
} }
else
printf("PList BIN writing succeeded\n");
printf("PList BIN writing succeeded\n");
plist_from_bin(plist_bin, size_out, &root_node2); plist_from_bin(plist_bin, size_out, &root_node2);
if (!root_node2) if (!root_node2)
{ {
printf("PList BIN parsing failed\n"); printf("PList BIN parsing failed\n");
return 5; return 5;
} }
else
printf("PList BIN parsing succeeded\n");
printf("PList BIN parsing succeeded\n");
plist_to_xml(root_node2, &plist_xml2, &size_out2); plist_to_xml(root_node2, &plist_xml2, &size_out2);
if (!plist_xml2) if (!plist_xml2)
{ {
printf("PList XML writing failed\n"); printf("PList XML writing failed\n");
return 8; return 8;
} }
else
printf("PList XML writing succeeded\n");
printf("PList XML writing succeeded\n");
if (plist_xml2) if (plist_xml2)
{ {
FILE *oplist = NULL; FILE *oplist = NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment