Commit e965b325 authored by Alexander Sack's avatar Alexander Sack Committed by Jonathan Beck

Fix armel floating point endianess (LP: #541879)

* on armel system floating poing data can have different endianess than
  rest of types; hence we fix arm endianess for defined(__VFP_FP__) to
  be big/native; this also applies for data parsing/writing
* date parsing didnt flip the endianess back for little endian systems
  when reading the values causing test failures; we fix this by ensuring
  float endianess is applied when parsing
parent 9bccdb30
...@@ -63,6 +63,22 @@ enum ...@@ -63,6 +63,22 @@ enum
BPLIST_MASK = 0xF0 BPLIST_MASK = 0xF0
}; };
static void float_byte_convert(uint8_t * address, size_t size)
{
#if G_BYTE_ORDER == G_LITTLE_ENDIAN && !defined (__VFP_FP__)
uint8_t i = 0, j = 0;
uint8_t tmp = 0;
for (i = 0; i < (size / 2); i++)
{
tmp = address[i];
j = ((size - 1) + 0) - i;
address[i] = address[j];
address[j] = tmp;
}
#endif
}
static void byte_convert(uint8_t * address, size_t size) static void byte_convert(uint8_t * address, size_t size)
{ {
#if G_BYTE_ORDER == G_LITTLE_ENDIAN #if G_BYTE_ORDER == G_LITTLE_ENDIAN
...@@ -136,23 +152,27 @@ static plist_t parse_real_node(char *bnode, uint8_t size) ...@@ -136,23 +152,27 @@ static plist_t parse_real_node(char *bnode, uint8_t size)
{ {
plist_data_t data = plist_new_plist_data(); plist_data_t data = plist_new_plist_data();
float floatval = 0.0; float floatval = 0.0;
uint8_t* buf;
size = 1 << size; // make length less misleading size = 1 << size; // make length less misleading
buf = malloc (size);
memcpy (buf, bnode, size);
switch (size) switch (size)
{ {
case sizeof(float): case sizeof(float):
floatval = *(float *) bnode; float_byte_convert(buf, size);
byte_convert((uint8_t *) & floatval, sizeof(float)); floatval = *(float *) buf;
data->realval = floatval; data->realval = floatval;
break; break;
case sizeof(double): case sizeof(double):
data->realval = *(double *) bnode; float_byte_convert(buf, size);
byte_convert((uint8_t *) & (data->realval), sizeof(double)); data->realval = *(double *) buf;
break; break;
default: default:
free(data); free(data);
return NULL; return NULL;
} }
free (buf);
data->type = PLIST_REAL; data->type = PLIST_REAL;
data->length = sizeof(double); data->length = sizeof(double);
...@@ -648,7 +668,7 @@ static void write_real(GByteArray * bplist, double val) ...@@ -648,7 +668,7 @@ static void write_real(GByteArray * bplist, double val)
float tmpval = (float) val; float tmpval = (float) val;
memcpy(buff + 1, &tmpval, size); memcpy(buff + 1, &tmpval, size);
} }
byte_convert(buff + 1, size); float_byte_convert(buff + 1, size);
g_byte_array_append(bplist, buff, sizeof(uint8_t) + size); g_byte_array_append(bplist, buff, sizeof(uint8_t) + size);
free(buff); free(buff);
} }
...@@ -659,7 +679,7 @@ static void write_date(GByteArray * bplist, double val) ...@@ -659,7 +679,7 @@ static void write_date(GByteArray * bplist, double val)
uint8_t *buff = (uint8_t *) malloc(sizeof(uint8_t) + size); uint8_t *buff = (uint8_t *) malloc(sizeof(uint8_t) + size);
buff[0] = BPLIST_DATE | Log2(size); buff[0] = BPLIST_DATE | Log2(size);
memcpy(buff + 1, &val, size); memcpy(buff + 1, &val, size);
byte_convert(buff + 1, size); float_byte_convert(buff + 1, size);
g_byte_array_append(bplist, buff, sizeof(uint8_t) + size); g_byte_array_append(bplist, buff, sizeof(uint8_t) + size);
free(buff); free(buff);
} }
......
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