diff options
author | Mike Buland <eichlan@xagasoft.com> | 2010-10-20 20:57:50 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2010-10-20 20:57:50 +0000 |
commit | ea9c6b32e952e1d87872b992989854e4899cb8f8 (patch) | |
tree | 25ae6579ed24f39888488f6f759a2783f1b44fa9 /src | |
parent | 811ab29d661266059abc28108d69c9a3e0b0fc88 (diff) | |
download | libgats-ea9c6b32e952e1d87872b992989854e4899cb8f8.tar.gz libgats-ea9c6b32e952e1d87872b992989854e4899cb8f8.tar.bz2 libgats-ea9c6b32e952e1d87872b992989854e4899cb8f8.tar.xz libgats-ea9c6b32e952e1d87872b992989854e4899cb8f8.zip |
Corrected a bug that made negative numbers between -64 and -127 inclusive
corrupt.
Diffstat (limited to 'src')
-rw-r--r-- | src/integer.h | 8 | ||||
-rw-r--r-- | 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 | |||
49 | if( iIn < 0 ) | 49 | if( iIn < 0 ) |
50 | { | 50 | { |
51 | iIn = -iIn; | 51 | iIn = -iIn; |
52 | b = (iIn&0x3F) | 0x40; | 52 | b = (iIn&0x3F); |
53 | if( iIn > b ) | ||
54 | b |= 0x80 | 0x40; | ||
53 | } | 55 | } |
54 | else | 56 | else |
55 | { | 57 | { |
56 | b = (iIn&0x3F); | 58 | b = (iIn&0x3F); |
59 | if( iIn > b ) | ||
60 | b |= 0x80; | ||
57 | } | 61 | } |
58 | if( iIn > b ) | ||
59 | b |= 0x80; | ||
60 | rStream.write( &b, 1 ); | 62 | rStream.write( &b, 1 ); |
61 | iIn = iIn >> 6; | 63 | iIn = iIn >> 6; |
62 | 64 | ||
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; | |||
8 | int main() | 8 | int main() |
9 | { | 9 | { |
10 | MemBuf mb; | 10 | MemBuf mb; |
11 | int64_t i = -53954321995838ll; | 11 | int64_t i = -(100); |
12 | 12 | ||
13 | sio << "Before: " << i << sio.nl; | 13 | sio << "Before: " << i << sio.nl; |
14 | Gats::Integer::writePackedInt( mb, i ); | 14 | Gats::Integer::writePackedInt( mb, i ); |
15 | mb.write("aaa", 3 ); | ||
15 | mb.setPos( 0 ); | 16 | mb.setPos( 0 ); |
16 | Gats::Integer::readPackedInt( mb, i ); | 17 | Gats::Integer::readPackedInt( mb, i ); |
17 | sio << "After: " << i << sio.nl; | 18 | sio << "After: " << i << sio.nl; |
19 | char buf[4]; | ||
20 | buf[mb.read( buf, 3 )] = '\0'; | ||
21 | sio << "Extra: \"" << buf << "\"" << sio.nl; | ||
18 | 22 | ||
19 | return 0; | 23 | return 0; |
20 | } | 24 | } |