summaryrefslogtreecommitdiffstats
path: root/src/bplist.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2016-09-19 01:49:05 +0200
committerGravatar Nikias Bassen2016-09-19 01:49:05 +0200
commit912cb45928f03355ca162a2f1286ca49eb58155c (patch)
tree2069bf08b56c04b3e194a3ac7515e897e2e12880 /src/bplist.c
parenta348ba9aa866e7e97fd7bf819af38c8c9107ebb5 (diff)
downloadlibplist-912cb45928f03355ca162a2f1286ca49eb58155c.tar.gz
libplist-912cb45928f03355ca162a2f1286ca49eb58155c.tar.bz2
Change internal storage of PLIST_DATE values from struct timeval to double
This removes the timeval union member from the plist_data_t structure. Since struct timeval is 2x64bit on 64bit platforms this member unnecessarily grew the union size to 16 bytes while a size of 8 bytes is sufficient. Also, on 32bit platforms struct timeval is only 2x32bit of size, limiting the range of possible time values. In addition the binary property list format also stores PLIST_DATE nodes as double.
Diffstat (limited to 'src/bplist.c')
-rw-r--r--src/bplist.c11
1 files changed, 2 insertions, 9 deletions
diff --git a/src/bplist.c b/src/bplist.c
index bb73b31..fbe1b63 100644
--- a/src/bplist.c
+++ b/src/bplist.c
@@ -284,11 +284,7 @@ static plist_t parse_date_node(const char **bnode, uint8_t size)
284 plist_t node = parse_real_node(bnode, size); 284 plist_t node = parse_real_node(bnode, size);
285 plist_data_t data = plist_get_data(node); 285 plist_data_t data = plist_get_data(node);
286 286
287 double time_real = data->realval;
288 data->timeval.tv_sec = (long) time_real;
289 data->timeval.tv_usec = (time_real - (long) time_real) * 1000000;
290 data->type = PLIST_DATE; 287 data->type = PLIST_DATE;
291 data->length = sizeof(struct timeval);
292 288
293 return node; 289 return node;
294} 290}
@@ -728,6 +724,7 @@ static unsigned int plist_data_hash(const void* key)
728 case PLIST_BOOLEAN: 724 case PLIST_BOOLEAN:
729 case PLIST_UINT: 725 case PLIST_UINT:
730 case PLIST_REAL: 726 case PLIST_REAL:
727 case PLIST_DATE:
731 case PLIST_UID: 728 case PLIST_UID:
732 buff = (char *) &data->intval; //works also for real as we use an union 729 buff = (char *) &data->intval; //works also for real as we use an union
733 size = 8; 730 size = 8;
@@ -744,10 +741,6 @@ static unsigned int plist_data_hash(const void* key)
744 buff = (char *) &key; 741 buff = (char *) &key;
745 size = sizeof(const void*); 742 size = sizeof(const void*);
746 break; 743 break;
747 case PLIST_DATE:
748 buff = (char *) &(data->timeval);
749 size = data->length;
750 break;
751 default: 744 default:
752 break; 745 break;
753 } 746 }
@@ -1183,7 +1176,7 @@ PLIST_API void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length)
1183 write_dict(bplist_buff, ptr_array_index(objects, i), ref_table, dict_param_size); 1176 write_dict(bplist_buff, ptr_array_index(objects, i), ref_table, dict_param_size);
1184 break; 1177 break;
1185 case PLIST_DATE: 1178 case PLIST_DATE:
1186 write_date(bplist_buff, data->timeval.tv_sec + (double) data->timeval.tv_usec / 1000000); 1179 write_date(bplist_buff, data->realval);
1187 break; 1180 break;
1188 case PLIST_UID: 1181 case PLIST_UID:
1189 write_uid(bplist_buff, data->intval); 1182 write_uid(bplist_buff, data->intval);