From 8a98d68933265f043bf95f9f273f9829619114c8 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 8 May 2012 14:14:21 -0700 Subject: convert: fixed sc8 convert issue w/ undefined behaviour Its important to use a signed cast when converting float to int. Then assign that signed int to an unsigned type of the same width. Its undefined behaviour when converting a negative float to an unsigned int. --- host/lib/convert/convert_common.hpp | 40 ++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 16 deletions(-) (limited to 'host') diff --git a/host/lib/convert/convert_common.hpp b/host/lib/convert/convert_common.hpp index 29ea94870..7626e4d87 100644 --- a/host/lib/convert/convert_common.hpp +++ b/host/lib/convert/convert_common.hpp @@ -194,11 +194,13 @@ static UHD_INLINE void item32_sc8_to_fc64(item32_t item, fc64_t &out0, fc64_t &o * Convert complex char to items32 sc8 buffer **********************************************************************/ static UHD_INLINE item32_t sc8_to_item32_sc8(sc8_t in0, sc8_t in1, double){ + boost::uint8_t real0 = boost::int8_t(in0.real()); + boost::uint8_t imag0 = boost::int8_t(in0.imag()); + boost::uint8_t real1 = boost::int8_t(in1.real()); + boost::uint8_t imag1 = boost::int8_t(in1.imag()); return - (item32_t(boost::uint8_t(in0.real())) << 8) | - (item32_t(boost::uint8_t(in0.imag())) << 0) | - (item32_t(boost::uint8_t(in1.real())) << 24) | - (item32_t(boost::uint8_t(in1.imag())) << 16) + (item32_t(real0) << 8) | (item32_t(imag0) << 0) | + (item32_t(real1) << 24) | (item32_t(imag1) << 16) ; } @@ -206,11 +208,13 @@ static UHD_INLINE item32_t sc8_to_item32_sc8(sc8_t in0, sc8_t in1, double){ * Convert complex short to items32 sc8 buffer **********************************************************************/ static UHD_INLINE item32_t sc16_to_item32_sc8(sc16_t in0, sc16_t in1, double){ + boost::uint8_t real0 = boost::int8_t(in0.real()); + boost::uint8_t imag0 = boost::int8_t(in0.imag()); + boost::uint8_t real1 = boost::int8_t(in1.real()); + boost::uint8_t imag1 = boost::int8_t(in1.imag()); return - (item32_t(boost::uint8_t(in0.real())) << 8) | - (item32_t(boost::uint8_t(in0.imag())) << 0) | - (item32_t(boost::uint8_t(in1.real())) << 24) | - (item32_t(boost::uint8_t(in1.imag())) << 16) + (item32_t(real0) << 8) | (item32_t(imag0) << 0) | + (item32_t(real1) << 24) | (item32_t(imag1) << 16) ; } @@ -218,11 +222,13 @@ static UHD_INLINE item32_t sc16_to_item32_sc8(sc16_t in0, sc16_t in1, double){ * Convert complex float to items32 sc8 buffer **********************************************************************/ static UHD_INLINE item32_t fc32_to_item32_sc8(fc32_t in0, fc32_t in1, double scale_factor){ + boost::uint8_t real0 = boost::int8_t(in0.real()*float(scale_factor)); + boost::uint8_t imag0 = boost::int8_t(in0.imag()*float(scale_factor)); + boost::uint8_t real1 = boost::int8_t(in1.real()*float(scale_factor)); + boost::uint8_t imag1 = boost::int8_t(in1.imag()*float(scale_factor)); return - (item32_t(boost::uint8_t(in0.real()*float(scale_factor))) << 8) | - (item32_t(boost::uint8_t(in0.imag()*float(scale_factor))) << 0) | - (item32_t(boost::uint8_t(in1.real()*float(scale_factor))) << 24) | - (item32_t(boost::uint8_t(in1.imag()*float(scale_factor))) << 16) + (item32_t(real0) << 8) | (item32_t(imag0) << 0) | + (item32_t(real1) << 24) | (item32_t(imag1) << 16) ; } @@ -230,11 +236,13 @@ static UHD_INLINE item32_t fc32_to_item32_sc8(fc32_t in0, fc32_t in1, double sca * Convert complex double to items32 sc8 buffer **********************************************************************/ static UHD_INLINE item32_t fc64_to_item32_sc8(fc64_t in0, fc64_t in1, double scale_factor){ + boost::uint8_t real0 = boost::int8_t(in0.real()*(scale_factor)); + boost::uint8_t imag0 = boost::int8_t(in0.imag()*(scale_factor)); + boost::uint8_t real1 = boost::int8_t(in1.real()*(scale_factor)); + boost::uint8_t imag1 = boost::int8_t(in1.imag()*(scale_factor)); return - (item32_t(boost::uint8_t(in0.real()*(scale_factor))) << 8) | - (item32_t(boost::uint8_t(in0.imag()*(scale_factor))) << 0) | - (item32_t(boost::uint8_t(in1.real()*(scale_factor))) << 24) | - (item32_t(boost::uint8_t(in1.imag()*(scale_factor))) << 16) + (item32_t(real0) << 8) | (item32_t(imag0) << 0) | + (item32_t(real1) << 24) | (item32_t(imag1) << 16) ; } -- cgit v1.2.3 From a6845bd0dd8cf34f0e62d7484267e7c581815af0 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 9 May 2012 18:29:48 -0700 Subject: n2xx: fix possible attribute error in netburner win_get_interfaces It is possible on some machines (at least one in this case), for adNode to not have the attribute next. Unexplained... This may be a fix, and if not, should be harmless. --- host/utils/usrp_n2xx_net_burner.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'host') diff --git a/host/utils/usrp_n2xx_net_burner.py b/host/utils/usrp_n2xx_net_burner.py index 835ab696f..f38a72fa1 100755 --- a/host/utils/usrp_n2xx_net_burner.py +++ b/host/utils/usrp_n2xx_net_burner.py @@ -205,9 +205,9 @@ def win_get_interfaces(): hexMask = struct.unpack("