Base64: realize decode() as template function

In Base64::decode() we mess around with pointers so it's more type-safe
to realize everything as a template function. This also silences compiler
warning about dereferencing type-punned pointer in Vibed plugin.
(cherry picked from commit 81cea79c38)
This commit is contained in:
Tobias Doerffel
2009-12-26 01:00:36 +01:00
parent 93eb03612d
commit 3348a4378f
2 changed files with 7 additions and 7 deletions

View File

@@ -2,8 +2,8 @@
* base64.h - namespace base64 with methods for encoding/decoding binary data
* to/from base64
*
* Copyright (c) 2006-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* Copyright (c) 2006-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
* This program is free software; you can redistribute it and/or
@@ -23,7 +23,6 @@
*
*/
#ifndef _BASE64_H
#define _BASE64_H
@@ -40,11 +39,12 @@ namespace base64
_dst = QByteArray( _data, _size ).toBase64();
}
inline void decode( const QString & _b64, char * * _data, int * _size )
template<class T>
inline void decode( const QString & _b64, T * * _data, int * _size )
{
QByteArray data = QByteArray::fromBase64( _b64.toAscii() );
QByteArray data = QByteArray::fromBase64( _b64.toUtf8() );
*_size = data.size();
*_data = new char[*_size];
*_data = new T[*_size / sizeof(T)];
memcpy( *_data, data.constData(), *_size );
}
// deprecated!!

View File

@@ -241,7 +241,7 @@ void vibed::loadSettings( const QDomElement & _this )
float * shp = 0;
base64::decode( _this.attribute( "graph" +
QString::number( i ) ),
(char * *) &shp,
&shp,
&size );
// TODO: check whether size == 128 * sizeof( float ),
// otherwise me might and up in a segfault