VarInt: fixed error with signed integer.

This commit is contained in:
Alexey Milovidov 2010-01-21 18:47:25 +00:00
parent 37d340b404
commit 156533bb1c
2 changed files with 17 additions and 2 deletions

View File

@ -27,12 +27,11 @@ inline void writeVarInt(Int x, std::ostream & ostr)
}
// TODO: здесь баг
/** Прочитать Int64, записанный в формате переменной длины (base128) */
inline void readVarInt(Int & x, std::istream & istr)
{
readVarUInt(*reinterpret_cast<UInt*>(&x), istr);
x = (x >> 1) ^ (x << 63);
x = (static_cast<UInt>(x) >> 1) ^ -(x & 1);
}

16
dbms/src/tests/varint.cpp Normal file
View File

@ -0,0 +1,16 @@
#include <iostream>
#include <sstream>
#include <Poco/Types.h>
#include <DB/VarInt.h>
#include <DB/Field.h>
int main(int argc, char ** argv)
{
DB::Int x = -1000000;
std::stringstream s;
DB::writeVarInt(x, s);
DB::readVarInt(x, s);
std::cout << x << std::endl;
return 0;
}