openddl-parser: latest greatest:
fix invalid handling of float values stored a hexadecimal literals. Signed-off-by: Kim Kulling <kim.kulling@googlemail.com>pull/536/head
parent
1899de6ea9
commit
14e65f5325
|
@ -46,6 +46,7 @@ namespace Grammar {
|
|||
static const char *BoolTrue = "true";
|
||||
static const char *BoolFalse = "false";
|
||||
static const char *RefToken = "ref";
|
||||
static const char *CommaSeparator = ",";
|
||||
|
||||
static const char* PrimitiveTypeToken[ Value::ddl_types_max ] = {
|
||||
"bool",
|
||||
|
@ -752,13 +753,16 @@ char *OpenDDLParser::parseHexaLiteral( char *in, char *end, Value **data ) {
|
|||
|
||||
int value( 0 );
|
||||
while( pos > 0 ) {
|
||||
int v = hex2Decimal( *start );
|
||||
pos--;
|
||||
value += hex2Decimal( *start ) * static_cast<int>( pow( 16.0, pos ) );
|
||||
value = ( value << 4 ) | v;
|
||||
start++;
|
||||
}
|
||||
|
||||
*data = ValueAllocator::allocPrimData( Value::ddl_int32 );
|
||||
(*data)->setInt32( value );
|
||||
*data = ValueAllocator::allocPrimData( Value::ddl_unsigned_int64 );
|
||||
if( ddl_nullptr != *data ) {
|
||||
( *data )->setUnsignedInt64( value );
|
||||
}
|
||||
|
||||
return in;
|
||||
}
|
||||
|
@ -856,7 +860,7 @@ char *OpenDDLParser::parseDataList( char *in, char *end, Value **data, size_t &n
|
|||
return in;
|
||||
}
|
||||
|
||||
DataArrayList *createDataArrayList( Value *currentValue, size_t numValues ) {
|
||||
static DataArrayList *createDataArrayList( Value *currentValue, size_t numValues ) {
|
||||
DataArrayList *dataList = new DataArrayList;
|
||||
dataList->m_dataList = currentValue;
|
||||
dataList->m_numItems = numValues;
|
||||
|
@ -892,7 +896,7 @@ char *OpenDDLParser::parseDataArrayList( char *in, char *end, DataArrayList **da
|
|||
}
|
||||
}
|
||||
}
|
||||
} while( ',' == *in && in != end );
|
||||
} while( Grammar::CommaSeparator[ 0 ] == *in && in != end );
|
||||
in = lookForNextToken( in, end );
|
||||
in++;
|
||||
}
|
||||
|
|
|
@ -88,6 +88,47 @@ int64 Value::getInt64() {
|
|||
return ( int64 ) ( *m_data );
|
||||
}
|
||||
|
||||
void Value::setUnsignedInt8( uint8 value ) {
|
||||
assert( ddl_unsigned_int8 == m_type );
|
||||
::memcpy( m_data, &value, m_size );
|
||||
}
|
||||
|
||||
uint8 Value::getUnsignedInt8() const {
|
||||
assert( ddl_unsigned_int8 == m_type );
|
||||
return ( uint8 ) ( *m_data );
|
||||
}
|
||||
|
||||
void Value::setUnsignedInt16( uint16 value ) {
|
||||
assert( ddl_unsigned_int16 == m_type );
|
||||
::memcpy( m_data, &value, m_size );
|
||||
|
||||
}
|
||||
uint16 Value::getUnsignedInt16() const {
|
||||
assert( ddl_unsigned_int16 == m_type );
|
||||
return ( uint8 ) ( *m_data );
|
||||
|
||||
}
|
||||
|
||||
void Value::setUnsignedInt32( uint32 value ) {
|
||||
assert( ddl_unsigned_int32 == m_type );
|
||||
::memcpy( m_data, &value, m_size );
|
||||
}
|
||||
|
||||
uint32 Value::getUnsignedInt32() const {
|
||||
assert( ddl_unsigned_int32 == m_type );
|
||||
return ( uint8 ) ( *m_data );
|
||||
}
|
||||
|
||||
void Value::setUnsignedInt64( uint64 value ) {
|
||||
assert( ddl_unsigned_int64 == m_type );
|
||||
::memcpy( m_data, &value, m_size );
|
||||
}
|
||||
|
||||
uint64 Value::getUnsignedInt64() const {
|
||||
assert( ddl_unsigned_int64 == m_type );
|
||||
return ( uint64 ) ( *m_data );
|
||||
}
|
||||
|
||||
void Value::setFloat( float value ) {
|
||||
assert( ddl_float == m_type );
|
||||
::memcpy( m_data, &value, m_size );
|
||||
|
|
|
@ -67,12 +67,52 @@ typedef char int8;
|
|||
typedef short int16;
|
||||
typedef int int32;
|
||||
typedef long int64;
|
||||
typedef unsigned char uint8;
|
||||
typedef unsigned short uint16;
|
||||
typedef unsigned int uint32;
|
||||
typedef unsigned long uint64;
|
||||
|
||||
enum NameType {
|
||||
GlobalName,
|
||||
LocalName
|
||||
};
|
||||
|
||||
struct Token {
|
||||
public:
|
||||
Token( const char *token )
|
||||
: m_token( token )
|
||||
, m_size( 0 ){
|
||||
if( ddl_nullptr != token ) {
|
||||
m_size = strlen( m_token );
|
||||
}
|
||||
}
|
||||
|
||||
~Token() {
|
||||
// empty
|
||||
}
|
||||
|
||||
size_t length() const {
|
||||
return m_size;
|
||||
}
|
||||
|
||||
bool operator == ( const Token &rhs ) const {
|
||||
if( m_size != rhs.m_size ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const int res( strncmp( m_token, rhs.m_token, m_size ) );
|
||||
return ( res == 0 );
|
||||
}
|
||||
|
||||
private:
|
||||
Token();
|
||||
Token( const Token & );
|
||||
Token &operator = ( const Token & );
|
||||
|
||||
private:
|
||||
const char *m_token;
|
||||
size_t m_size;
|
||||
};
|
||||
struct Name {
|
||||
NameType m_type;
|
||||
Identifier *m_id;
|
||||
|
|
|
@ -227,17 +227,18 @@ static T *getNextSeparator( T *in, T *end ) {
|
|||
return in;
|
||||
}
|
||||
|
||||
static const int ErrorHex2Decimal = 9999;
|
||||
static const int ErrorHex2Decimal = 9999999;
|
||||
|
||||
inline
|
||||
int hex2Decimal( char in ) {
|
||||
if( isNumeric( in ) ) {
|
||||
return (int) in-48;
|
||||
return ( in - 48 );
|
||||
}
|
||||
|
||||
char hexCodeLower( 'a' ), hexCodeUpper( 'A' );
|
||||
for( int i = 0; i<16; i++ ) {
|
||||
if( in == hexCodeLower + i || in == hexCodeUpper + i ) {
|
||||
return i+10;
|
||||
return ( i+10 );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -66,11 +66,19 @@ public:
|
|||
void setInt8( int8 value );
|
||||
int8 getInt8();
|
||||
void setInt16( int16 value );
|
||||
int16 getInt16();
|
||||
int16 getInt16();
|
||||
void setInt32( int32 value );
|
||||
int32 getInt32();
|
||||
int32 getInt32();
|
||||
void setInt64( int64 value );
|
||||
int64 getInt64();
|
||||
int64 getInt64();
|
||||
void setUnsignedInt8( uint8 value );
|
||||
uint8 getUnsignedInt8() const;
|
||||
void setUnsignedInt16( uint16 value );
|
||||
uint16 getUnsignedInt16() const;
|
||||
void setUnsignedInt32( uint32 value );
|
||||
uint32 getUnsignedInt32() const;
|
||||
void setUnsignedInt64( uint64 value );
|
||||
uint64 getUnsignedInt64() const;
|
||||
void setFloat( float value );
|
||||
float getFloat() const;
|
||||
void setDouble( double value );
|
||||
|
|
Loading…
Reference in New Issue