From 3348a4378f9e07f08f7a64fd78619f8762d65bce Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Sat, 26 Dec 2009 01:00:36 +0100 Subject: [PATCH] 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 81cea79c38f57a0d26793ad995b305aa4ef2b6dc) --- include/base64.h | 12 ++++++------ plugins/vibed/vibed.cpp | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/base64.h b/include/base64.h index 74578684f..ebdfe47b3 100644 --- a/include/base64.h +++ b/include/base64.h @@ -2,8 +2,8 @@ * base64.h - namespace base64 with methods for encoding/decoding binary data * to/from base64 * - * Copyright (c) 2006-2008 Tobias Doerffel - * + * Copyright (c) 2006-2009 Tobias Doerffel + * * 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 + 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!! diff --git a/plugins/vibed/vibed.cpp b/plugins/vibed/vibed.cpp index f6630ec58..29206f865 100644 --- a/plugins/vibed/vibed.cpp +++ b/plugins/vibed/vibed.cpp @@ -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