r17069 - gnucash/branches/gda-dev2/src/backend/gda - Fix segmentation fault when loading/saving 64 bit integers
Phil Longstaff
plongstaff at cvs.gnucash.org
Sun Apr 6 13:26:43 EDT 2008
Author: plongstaff
Date: 2008-04-06 13:26:43 -0400 (Sun, 06 Apr 2008)
New Revision: 17069
Trac: http://svn.gnucash.org/trac/changeset/17069
Modified:
gnucash/branches/gda-dev2/src/backend/gda/gnc-backend-util-gda.c
gnucash/branches/gda-dev2/src/backend/gda/gnc-slots-gda.c
Log:
Fix segmentation fault when loading/saving 64 bit integers
Modified: gnucash/branches/gda-dev2/src/backend/gda/gnc-backend-util-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/gda/gnc-backend-util-gda.c 2008-04-06 15:26:19 UTC (rev 17068)
+++ gnucash/branches/gda-dev2/src/backend/gda/gnc-backend-util-gda.c 2008-04-06 17:26:43 UTC (rev 17069)
@@ -458,6 +458,8 @@
{ load_boolean, create_boolean_col,
get_gvalue_boolean_for_query, get_gvalue_boolean_cond };
/* ----------------------------------------------------------------- */
+typedef gint64 (*Int64AccessFunc)( const gpointer );
+typedef void (*Int64SetterFunc)( const gpointer, gint64 );
static void
load_int64( const GncGdaBackend* be, GdaDataModel* pModel, gint row,
@@ -465,30 +467,29 @@
const col_cvt_t* table_row )
{
const GValue* val;
- gint64 i64_value;
+ gint64 i64_value = 0;
+ Int64SetterFunc i64_setter = (Int64SetterFunc)setter;
g_return_if_fail( be != NULL );
g_return_if_fail( pModel != NULL );
g_return_if_fail( row >= 0 );
+ g_return_if_fail( setter != NULL );
g_return_if_fail( pObject != NULL );
g_return_if_fail( table_row != NULL );
val = gda_data_model_get_value_at_col_name( pModel, table_row->col_name, row );
- if( gda_value_is_null( val ) ) {
- (*setter)( pObject, NULL );
- } else {
+ if( !gda_value_is_null( val ) ) {
i64_value = g_value_get_int64( val );
- (*setter)( pObject, (gpointer)&i64_value );
}
+ (*i64_setter)( pObject, i64_value );
}
static void
get_gvalue_int64( const GncGdaBackend* be, QofIdTypeConst obj_name, const gpointer pObject,
const col_cvt_t* table_row, GValue* value )
{
- gint64* pInt64;
gint64 i64_value;
- QofAccessFunc getter;
+ Int64AccessFunc getter;
g_return_if_fail( be != NULL );
g_return_if_fail( obj_name != NULL );
@@ -497,13 +498,10 @@
g_return_if_fail( value != NULL );
memset( value, 0, sizeof( GValue ) );
- getter = gnc_gda_get_getter( obj_name, table_row );
- pInt64 = (*getter)( pObject, NULL );
- if( pInt64 != NULL ) {
- i64_value = *pInt64;
- g_value_init( value, G_TYPE_INT64 );
- g_value_set_int64( value, i64_value );
- }
+ getter = (Int64AccessFunc)gnc_gda_get_getter( obj_name, table_row );
+ i64_value = (*getter)( pObject );
+ g_value_init( value, G_TYPE_INT64 );
+ g_value_set_int64( value, i64_value );
}
static void
Modified: gnucash/branches/gda-dev2/src/backend/gda/gnc-slots-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/gda/gnc-slots-gda.c 2008-04-06 15:26:19 UTC (rev 17068)
+++ gnucash/branches/gda-dev2/src/backend/gda/gnc-slots-gda.c 2008-04-06 17:26:43 UTC (rev 17069)
@@ -57,8 +57,8 @@
static void set_path( gpointer pObject, gpointer pValue );
static gpointer get_slot_type( gpointer pObject, const QofParam* param );
static void set_slot_type( gpointer pObject, gpointer pValue );
-static gpointer get_int64_val( gpointer pObject, const QofParam* param );
-static void set_int64_val( gpointer pObject, gpointer pValue );
+static gint64 get_int64_val( gpointer pObject, const QofParam* param );
+static void set_int64_val( gpointer pObject, gint64 pValue );
static gpointer get_string_val( gpointer pObject, const QofParam* param );
static void set_string_val( gpointer pObject, gpointer pValue );
static gpointer get_double_val( gpointer pObject, const QofParam* param );
@@ -82,7 +82,7 @@
{ "slot_type", CT_INT, 0, COL_NNUL, NULL, NULL,
get_slot_type, set_slot_type, },
{ "int64_val", CT_INT64, 0, 0, NULL, NULL,
- get_int64_val, set_int64_val },
+ (QofAccessFunc)get_int64_val, (QofSetterFunc)set_int64_val },
{ "string_val", CT_STRING, SLOT_MAX_PATHNAME_LEN, 0, NULL, NULL,
get_string_val, set_string_val },
{ "double_val", CT_DOUBLE, 0, 0, NULL, NULL,
@@ -164,31 +164,29 @@
pInfo->value_type = (KvpValueType)pValue;
}
-static gpointer
+static gint64
get_int64_val( gpointer pObject, const QofParam* param )
{
slot_info_t* pInfo = (slot_info_t*)pObject;
- static gint64 i64_val;
- g_return_val_if_fail( pObject != NULL, NULL );
+ g_return_val_if_fail( pObject != NULL, 0 );
if( kvp_value_get_type( pInfo->pKvpValue ) == KVP_TYPE_GINT64 ) {
- i64_val = kvp_value_get_gint64( pInfo->pKvpValue );
- return &i64_val;
+ return kvp_value_get_gint64( pInfo->pKvpValue );
} else {
- return NULL;
+ return 0;
}
}
static void
-set_int64_val( gpointer pObject, gpointer pValue )
+set_int64_val( gpointer pObject, gint64 value )
{
slot_info_t* pInfo = (slot_info_t*)pObject;
g_return_if_fail( pObject != NULL );
- if( pInfo->value_type == KVP_TYPE_GINT64 && pValue != NULL ) {
- kvp_frame_set_gint64( pInfo->pKvpFrame, pInfo->path->str, *(gint64*)pValue );
+ if( pInfo->value_type == KVP_TYPE_GINT64 ) {
+ kvp_frame_set_gint64( pInfo->pKvpFrame, pInfo->path->str, value );
}
}
More information about the gnucash-changes
mailing list