From ea9c6b32e952e1d87872b992989854e4899cb8f8 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 20 Oct 2010 20:57:50 +0000 Subject: Corrected a bug that made negative numbers between -64 and -127 inclusive corrupt. --- src/integer.h | 8 +++++--- src/tests/int.cpp | 6 +++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/integer.h b/src/integer.h index be7c808..014b53a 100644 --- a/src/integer.h +++ b/src/integer.h @@ -49,14 +49,16 @@ namespace Gats if( iIn < 0 ) { iIn = -iIn; - b = (iIn&0x3F) | 0x40; + b = (iIn&0x3F); + if( iIn > b ) + b |= 0x80 | 0x40; } else { b = (iIn&0x3F); + if( iIn > b ) + b |= 0x80; } - if( iIn > b ) - b |= 0x80; rStream.write( &b, 1 ); iIn = iIn >> 6; diff --git a/src/tests/int.cpp b/src/tests/int.cpp index 5d5b7d2..1601578 100644 --- a/src/tests/int.cpp +++ b/src/tests/int.cpp @@ -8,13 +8,17 @@ using namespace Bu; int main() { MemBuf mb; - int64_t i = -53954321995838ll; + int64_t i = -(100); sio << "Before: " << i << sio.nl; Gats::Integer::writePackedInt( mb, i ); + mb.write("aaa", 3 ); mb.setPos( 0 ); Gats::Integer::readPackedInt( mb, i ); sio << "After: " << i << sio.nl; + char buf[4]; + buf[mb.read( buf, 3 )] = '\0'; + sio << "Extra: \"" << buf << "\"" << sio.nl; return 0; } -- cgit v1.2.3