[Opensrf-commits] r1733 - trunk/src/libopensrf (scottmk)
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Aug 5 18:27:10 EDT 2009
Author: scottmk
Date: 2009-08-05 18:27:04 -0400 (Wed, 05 Aug 2009)
New Revision: 1733
Modified:
trunk/src/libopensrf/osrf_json_object.c
Log:
Extended the JSON_INIT_CLEAR macro to avoid segfaults.
Scenario: converting a JSON_BOOL, with a value of true, to a JSON_HASH or
JSON_ARRAY. The true value (in a union with an osrfHash* and an osrfList*)
was being interpreted as a non_NULL pointer and deferenced. Oops.
With this change, we clear the boolean value (by nullifying one of the
unioned pointers) whenever changing from a JSON_BOOL to anything else.
Modified: trunk/src/libopensrf/osrf_json_object.c
===================================================================
--- trunk/src/libopensrf/osrf_json_object.c 2009-08-05 12:53:19 UTC (rev 1732)
+++ trunk/src/libopensrf/osrf_json_object.c 2009-08-05 22:27:04 UTC (rev 1733)
@@ -28,21 +28,23 @@
if( _obj_->type == JSON_HASH && newtype != JSON_HASH ) { \
osrfHashFree(_obj_->value.h); \
_obj_->value.h = NULL; \
-} else if( _obj_->type == JSON_ARRAY && newtype != JSON_ARRAY ) { \
+ } else if( _obj_->type == JSON_ARRAY && newtype != JSON_ARRAY ) { \
osrfListFree(_obj_->value.l); \
_obj_->value.l = NULL; \
-} else if( _obj_->type == JSON_STRING || _obj_->type == JSON_NUMBER ) { \
- free(_obj_->value.s); \
+ } else if( _obj_->type == JSON_STRING || _obj_->type == JSON_NUMBER ) { \
+ free(_obj_->value.s); \
_obj_->value.s = NULL; \
-} \
- _obj_->type = newtype;\
+ } else if( _obj_->type == JSON_BOOL && newtype != JSON_BOOL ) { \
+ _obj_->value.l = NULL; \
+ } \
+ _obj_->type = newtype; \
if( newtype == JSON_HASH && _obj_->value.h == NULL ) { \
_obj_->value.h = osrfNewHash(); \
osrfHashSetCallback( _obj_->value.h, _jsonFreeHashItem ); \
-} else if( newtype == JSON_ARRAY && _obj_->value.l == NULL ) { \
+ } else if( newtype == JSON_ARRAY && _obj_->value.l == NULL ) { \
_obj_->value.l = osrfNewList(); \
_obj_->value.l->freeItem = _jsonFreeListItem;\
-}
+ }
static int unusedObjCapture = 0;
static int unusedObjRelease = 0;
More information about the opensrf-commits
mailing list