1
0
Fork 0

Fix creating of a copy of Value in GetValue. Fixes crashes with freeing the returned string.

Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@3089
This commit is contained in:
Peter Veenstra 2008-01-27 18:31:01 +00:00
parent e0c08be26f
commit 8a10bb8f0d
2 changed files with 16 additions and 14 deletions

View file

@ -16,7 +16,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* $Id: setup.h,v 1.30 2008-01-26 15:50:19 qbix79 Exp $ */
/* $Id: setup.h,v 1.31 2008-01-27 18:31:01 qbix79 Exp $ */
#ifndef DOSBOX_SETUP_H
#define DOSBOX_SETUP_H
@ -47,6 +47,8 @@
#include <string>
#endif
#pragma warning(disable: 4290)
class Hex {
private:
int _hex;
@ -89,11 +91,11 @@ public:
Value& operator= (Value const& in) throw(WrongType) { return copy(Value(in));}
bool operator== (Value const & other);
operator bool () throw(WrongType);
operator Hex () throw(WrongType);
operator int () throw(WrongType);
operator double () throw(WrongType);
operator char const* () throw(WrongType);
operator bool () const throw(WrongType);
operator Hex () const throw(WrongType);
operator int () const throw(WrongType);
operator double () const throw(WrongType);
operator char const* () const throw(WrongType);
private:
void destroy();
@ -108,7 +110,7 @@ public:
Property(char const * const _propname):propname(_propname) { }
virtual void SetValue(char* input)=0;
virtual void GetValuestring(char* str) const=0;
Value GetValue() const { return value;}
Value const& GetValue() const { return value;}
virtual ~Property(){ }
std::string propname;
//CheckValue returns true (and sets value to in) if value is in suggested_values;
@ -141,7 +143,7 @@ private:
};
class Prop_double:public Property {
public:
Prop_double(char const * const _propname, float _value):Property(_propname){
Prop_double(char const * const _propname, double _value):Property(_propname){
default_value = value = _value;
}
void SetValue(char* input);

View file

@ -16,7 +16,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* $Id: setup.cpp,v 1.42 2008-01-26 15:50:19 qbix79 Exp $ */
/* $Id: setup.cpp,v 1.43 2008-01-27 18:31:01 qbix79 Exp $ */
#include "dosbox.h"
#include "cross.h"
@ -52,27 +52,27 @@ void Value::plaincopy(Value const& in) {
if(type == V_STRING) _string = new string(*in._string);
}
Value::operator bool () throw(WrongType) {
Value::operator bool () const throw(WrongType) {
if(type != V_BOOL) throw WrongType();
return _bool;
}
Value::operator Hex () throw(WrongType) {
Value::operator Hex () const throw(WrongType) {
if(type != V_HEX) throw WrongType();
return _hexn;
}
Value::operator int () throw(WrongType) {
Value::operator int () const throw(WrongType) {
if(type != V_INT) throw WrongType();
return _int;
}
Value::operator double () throw(WrongType) {
Value::operator double () const throw(WrongType) {
if(type != V_DOUBLE) throw WrongType();
return _double;
}
Value::operator char const* () throw(WrongType) {
Value::operator char const* () const throw(WrongType) {
if(type != V_STRING) throw WrongType();
return _string->c_str();
}