ref: 54f506213757c88975ebe6ddda65abcc2b2c89d0
parent: 71a9a855e81f4ef0698eabcdb4cbc7382feea5b3
author: cbagwell <cbagwell>
date: Wed Sep 29 22:42:10 EDT 2004
Tracked float swap bug down to byteswap.h usage. Revert to using internal version of st_swapf.
--- a/src/misc.c
+++ b/src/misc.c
@@ -240,16 +240,12 @@
/* Read float. */
int st_readf(ft_t ft, float *f)
{
- uint32_t datum, *dp;
-
- dp = &datum;
- if (st_read(ft, dp, sizeof(float), 1) != 1)
+ if (st_read(ft, f, sizeof(float), 1) != 1)
{
return(ST_EOF);
}
if (ft->swap)
- datum = st_swapdw(datum);
- *f = *((float *)dp);
+ *f = st_swapf(*f);
return ST_SUCCESS;
}
@@ -271,20 +267,12 @@
/* Read double. */
int st_readdf(ft_t ft, double *d)
{
- uint32_t datum[2], *dp;
-
- dp = &datum[0];
- if (st_read(ft, dp, sizeof(double), 1) != 1)
+ if (st_read(ft, d, sizeof(double), 1) != 1)
{
return(ST_EOF);
}
if (ft->swap)
- {
- datum[0] = st_swapd(datum[0]);
- datum[1] = st_swapd(datum[1]);
- }
- *d = *((float *)dp);
-
+ *d = st_swapd(*d);
return ST_SUCCESS;
}
@@ -324,6 +312,8 @@
return (udw >> 24) | ((udw >> 8) & 0xff00) | ((udw << 8) & 0xff0000L) | (udw << 24);
}
+#endif
+
/* return swapped 32-bit float */
float st_swapf(float f)
{
@@ -337,7 +327,6 @@
return u.f;
}
-#endif
uint32_t st_swap24(uint32_t udw)
{
--- a/src/raw.c
+++ b/src/raw.c
@@ -301,17 +301,12 @@
while (len)
{
float datum;
- uint32_t int_datum, *ip;
- /* If swapping is needed, do this before converting to a float. */
- int_datum = *((uint32_t *)buf2);
+ datum = *((float *)buf2);
buf2++; buf2++; buf2++; buf2++;
if (swap)
- int_datum = st_swapdw(int_datum);
+ datum = st_swapf(datum);
- ip = &int_datum;
- datum = *((float *)ip);
-
*buf1++ = ST_FLOAT_DWORD_TO_SAMPLE(datum);
len--;
}
@@ -322,23 +317,12 @@
while (len)
{
double datum;
- uint32_t int_datum[2], *ip;
- /* If swapping needs to occur, do this before moving into
- * float data.
- */
- int_datum[0] = *((uint32_t *)buf2);
+ datum = *((double *)buf2);
buf2++; buf2++; buf2++; buf2++;
- if (swap)
- int_datum[0] = st_swapdw(int_datum[0]);
-
- int_datum[1] = *((uint32_t *)buf2);
buf2++; buf2++; buf2++; buf2++;
if (swap)
- int_datum[1] = st_swapdw(int_datum[1]);
-
- ip = &int_datum[0];
- datum = *((double *)ip);
+ datum = st_swapd(datum);
*buf1++ = ST_FLOAT_DDWORD_TO_SAMPLE(datum);
len--;
--- a/src/st_i.h
+++ b/src/st_i.h
@@ -94,12 +94,11 @@
#ifdef HAVE_BYTESWAP_H
#define st_swapw(x) bswap_16(x)
#define st_swapdw(x) bswap_32(x)
-#define st_swapf(x) (float)bswap_32((uint32_t)(x))
#else
uint16_t st_swapw(uint16_t uw);
uint32_t st_swapdw(uint32_t udw);
-float st_swapf(float f);
#endif
+float st_swapf(float f);
uint32_t st_swap24(uint32_t udw);
double st_swapd(double d);