Skip to content

Commit 15f1458

Browse files
Check result of Value.read calls
1 parent 78e73cf commit 15f1458

File tree

4 files changed

+49
-17
lines changed

4 files changed

+49
-17
lines changed

src/interface/value.i

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,10 @@ static swig_type_info* get_swig_type(Exiv2::Value* value) {
182182
%extend Exiv2::AsciiValue {
183183
AsciiValue(const std::string &buf) {
184184
Exiv2::AsciiValue* self = new Exiv2::AsciiValue();
185-
self->read(buf);
185+
if (self->read(buf)) {
186+
delete self;
187+
return NULL;
188+
}
186189
return self;
187190
}
188191
}
@@ -523,7 +526,10 @@ RAW_STRING_DATA(Exiv2::XmpTextValue)
523526
new Exiv2::XmpArrayValue(typeId_xmpBag);
524527
for (std::vector<std::string>::const_iterator i = value.begin();
525528
i != value.end(); ++i) {
526-
result->read(*i);
529+
if (result->read(*i)) {
530+
delete result;
531+
return NULL;
532+
}
527533
}
528534
return result;
529535
}
@@ -534,8 +540,12 @@ RAW_STRING_DATA(Exiv2::XmpTextValue)
534540
std::string __getitem__(long idx) {
535541
return $self->toString(idx);
536542
}
537-
void append(std::string value) {
538-
$self->read(value);
543+
PyObject* append(std::string value) {
544+
int error = $self->read(value);
545+
if (error)
546+
return PyErr_Format(PyExc_RuntimeError,
547+
"XmpArrayValue.read returned %d", error);
548+
return SWIG_Py_Void();
539549
}
540550
}
541551
%ignore Exiv2::XmpArrayValue::XmpArrayValue();

src/swig-0_27_7/value_wrap.cxx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6101,7 +6101,10 @@ SWIGINTERN char const *Exiv2_StringValueBase_data(Exiv2::StringValueBase *self){
61016101
}
61026102
SWIGINTERN Exiv2::AsciiValue *new_Exiv2_AsciiValue__SWIG_1(std::string const &buf){
61036103
Exiv2::AsciiValue* self = new Exiv2::AsciiValue();
6104-
self->read(buf);
6104+
if (self->read(buf)) {
6105+
delete self;
6106+
return NULL;
6107+
}
61056108
return self;
61066109
}
61076110

@@ -6470,7 +6473,10 @@ SWIGINTERN Exiv2::XmpArrayValue *new_Exiv2_XmpArrayValue__SWIG_0(std::vector< st
64706473
new Exiv2::XmpArrayValue(typeId_xmpBag);
64716474
for (std::vector<std::string>::const_iterator i = value.begin();
64726475
i != value.end(); ++i) {
6473-
result->read(*i);
6476+
if (result->read(*i)) {
6477+
delete result;
6478+
return NULL;
6479+
}
64746480
}
64756481
return result;
64766482
}
@@ -6480,8 +6486,12 @@ SWIGINTERN Exiv2::XmpArrayValue *new_Exiv2_XmpArrayValue__SWIG_1(Exiv2::TypeId t
64806486
SWIGINTERN std::string Exiv2_XmpArrayValue___getitem__(Exiv2::XmpArrayValue *self,long idx){
64816487
return self->toString(idx);
64826488
}
6483-
SWIGINTERN void Exiv2_XmpArrayValue_append(Exiv2::XmpArrayValue *self,std::string value){
6484-
self->read(value);
6489+
SWIGINTERN PyObject *Exiv2_XmpArrayValue_append(Exiv2::XmpArrayValue *self,std::string value){
6490+
int error = self->read(value);
6491+
if (error)
6492+
return PyErr_Format(PyExc_RuntimeError,
6493+
"XmpArrayValue.read returned %d", error);
6494+
return SWIG_Py_Void();
64856495
}
64866496

64876497
namespace swig {
@@ -12115,6 +12125,7 @@ SWIGINTERN PyObject *_wrap_XmpArrayValue_append(PyObject *self, PyObject *args)
1211512125
void *argp1 = 0 ;
1211612126
int res1 = 0 ;
1211712127
PyObject * obj1 = 0 ;
12128+
PyObject *result = 0 ;
1211812129

1211912130
if (!PyArg_UnpackTuple(args, "XmpArrayValue_append", 1, 1, &obj1)) SWIG_fail;
1212012131
res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_Exiv2__XmpArrayValue, 0 | 0 );
@@ -12131,8 +12142,8 @@ SWIGINTERN PyObject *_wrap_XmpArrayValue_append(PyObject *self, PyObject *args)
1213112142
arg2 = *ptr;
1213212143
if (SWIG_IsNewObj(res)) delete ptr;
1213312144
}
12134-
Exiv2_XmpArrayValue_append(arg1,SWIG_STD_MOVE(arg2));
12135-
resultobj = SWIG_Py_Void();
12145+
result = (PyObject *)Exiv2_XmpArrayValue_append(arg1,SWIG_STD_MOVE(arg2));
12146+
resultobj = result;
1213612147
return resultobj;
1213712148
fail:
1213812149
return NULL;

src/swig-0_28_5/value_wrap.cxx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6271,7 +6271,10 @@ SWIGINTERN char const *Exiv2_StringValueBase_data(Exiv2::StringValueBase *self){
62716271
}
62726272
SWIGINTERN Exiv2::AsciiValue *new_Exiv2_AsciiValue__SWIG_1(std::string const &buf){
62736273
Exiv2::AsciiValue* self = new Exiv2::AsciiValue();
6274-
self->read(buf);
6274+
if (self->read(buf)) {
6275+
delete self;
6276+
return NULL;
6277+
}
62756278
return self;
62766279
}
62776280

@@ -6640,7 +6643,10 @@ SWIGINTERN Exiv2::XmpArrayValue *new_Exiv2_XmpArrayValue__SWIG_0(std::vector< st
66406643
new Exiv2::XmpArrayValue(typeId_xmpBag);
66416644
for (std::vector<std::string>::const_iterator i = value.begin();
66426645
i != value.end(); ++i) {
6643-
result->read(*i);
6646+
if (result->read(*i)) {
6647+
delete result;
6648+
return NULL;
6649+
}
66446650
}
66456651
return result;
66466652
}
@@ -6650,8 +6656,12 @@ SWIGINTERN Exiv2::XmpArrayValue *new_Exiv2_XmpArrayValue__SWIG_1(Exiv2::TypeId t
66506656
SWIGINTERN std::string Exiv2_XmpArrayValue___getitem__(Exiv2::XmpArrayValue *self,long idx){
66516657
return self->toString(idx);
66526658
}
6653-
SWIGINTERN void Exiv2_XmpArrayValue_append(Exiv2::XmpArrayValue *self,std::string value){
6654-
self->read(value);
6659+
SWIGINTERN PyObject *Exiv2_XmpArrayValue_append(Exiv2::XmpArrayValue *self,std::string value){
6660+
int error = self->read(value);
6661+
if (error)
6662+
return PyErr_Format(PyExc_RuntimeError,
6663+
"XmpArrayValue.read returned %d", error);
6664+
return SWIG_Py_Void();
66556665
}
66566666

66576667
namespace swig {
@@ -12433,6 +12443,7 @@ SWIGINTERN PyObject *_wrap_XmpArrayValue_append(PyObject *self, PyObject *args)
1243312443
void *argp1 = 0 ;
1243412444
int res1 = 0 ;
1243512445
PyObject * obj1 = 0 ;
12446+
PyObject *result = 0 ;
1243612447

1243712448
if (!PyArg_UnpackTuple(args, "XmpArrayValue_append", 1, 1, &obj1)) SWIG_fail;
1243812449
res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_Exiv2__XmpArrayValue, 0 | 0 );
@@ -12449,8 +12460,8 @@ SWIGINTERN PyObject *_wrap_XmpArrayValue_append(PyObject *self, PyObject *args)
1244912460
arg2 = *ptr;
1245012461
if (SWIG_IsNewObj(res)) delete ptr;
1245112462
}
12452-
Exiv2_XmpArrayValue_append(arg1,SWIG_STD_MOVE(arg2));
12453-
resultobj = SWIG_Py_Void();
12463+
result = (PyObject *)Exiv2_XmpArrayValue_append(arg1,SWIG_STD_MOVE(arg2));
12464+
resultobj = result;
1245412465
return resultobj;
1245512466
fail:
1245612467
return NULL;

tests/test_value.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ def do_test_TimeValue(self, py_time):
466466
if seconds < 0:
467467
seconds += 24 * 3600
468468
value = exiv2.TimeValue()
469-
value.read(py_time.isoformat())
469+
self.assertEqual(value.read(py_time.isoformat()), 0)
470470
self.do_common_tests(value, exiv2.TypeId.time, py_time.isoformat(), data)
471471
self.do_conversion_tests(value, py_time.isoformat(), seconds)
472472
self.do_dataarea_tests(value)

0 commit comments

Comments
 (0)