Skip to content

Commit

Permalink
Correct the handling of null method_hash_table pointers
Browse files Browse the repository at this point in the history
Change-Id: I4a5e5a3e7d0f0320ddd7eab3125e64a1b794dbc6
  • Loading branch information
DrWEbOS authored and Gerrit Code Review committed Aug 5, 2012
1 parent 95d8c16 commit 10c58ad
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
42 changes: 27 additions & 15 deletions src/device/nyx_device_impl.c
Expand Up @@ -340,14 +340,20 @@ nyx_error_t nyx_device_close(nyx_device_handle_t handle)
nyx_error_t error = close_ptr(d);

/*
* let's destroy the method hash table.
* let's destroy the method hash table if necessary.
*/
if (method_hash_table)
if (method_hash_table) {
g_hash_table_destroy (method_hash_table);
if (name)
d->method_hash_table = NULL;
}
if (name) {
free (name);
if (desc)
name = NULL;
}
if (desc) {
free (desc);
desc = NULL;
}

/*
* We are done so, we can close the module.
Expand Down Expand Up @@ -418,32 +424,38 @@ nyx_error_t nyx_device_set_report_rate(nyx_device_handle_t handle, nyx_report_ra
nyx_device_t* d = (nyx_device_t*)handle;
CHECK_DEVICE(d);
nyx_set_report_rate_function_t f = LOOKUP_METHOD(d, NYX_SET_REPORT_RATE_MODULE_METHOD);
if (f)
if (f) {
return f(d,rate);
else
}
else {
return NYX_ERROR_NOT_IMPLEMENTED;
}
}

nyx_error_t nyx_device_get_report_rate(nyx_device_handle_t handle, nyx_report_rate_t *rate_out_ptr)
{
nyx_device_t* d = (nyx_device_t*)handle;
CHECK_DEVICE(d);
nyx_get_report_rate_function_t f = LOOKUP_METHOD(d, NYX_GET_REPORT_RATE_MODULE_METHOD);
if (f)
if (f) {
return f(d,rate_out_ptr);
else
}
else {
return NYX_ERROR_NOT_IMPLEMENTED;
}
}

nyx_error_t nyx_device_set_property(nyx_device_handle_t handle, const char* property_name_in, void* property_value_in_ptr)
{
nyx_device_t* d = (nyx_device_t*)handle;
CHECK_DEVICE(d);
nyx_set_property_function_t f = LOOKUP_METHOD(d, NYX_SET_PROPERTY_MODULE_METHOD);
if (f)
return f(d,property_name_in, property_value_in_ptr);
else
return NYX_ERROR_NOT_IMPLEMENTED;
nyx_device_t* d = (nyx_device_t*)handle;
CHECK_DEVICE(d);
nyx_set_property_function_t f = LOOKUP_METHOD(d, NYX_SET_PROPERTY_MODULE_METHOD);
if (f) {
return f(d,property_name_in, property_value_in_ptr);
}
else {
return NYX_ERROR_NOT_IMPLEMENTED;
}
}

nyx_error_t nyx_device_get_property(nyx_device_handle_t handle, const char* property_name_in, void** property_value_out_ptr)
Expand Down
10 changes: 7 additions & 3 deletions src/device/nyx_device_impl.h
Expand Up @@ -44,8 +44,12 @@
nyx_error ("method " #_method " not implemented"); \
return NYX_ERROR_NOT_IMPLEMENTED; \
}}
#define LOOKUP_METHOD(_d,_method) g_hash_table_lookup ((GHashTable*)_d->method_hash_table, GINT_TO_POINTER(_method))

/* FIXME: This null pointer check is a workaround that averts additional
glib error messages from the output in the case of any badly written
test logic that passes in a null table (glib returns zero anyway in
this same scenario) */
#define LOOKUP_METHOD(_d,_method) \
(((GHashTable*)_d->method_hash_table == NULL) ? 0 : (g_hash_table_lookup ((GHashTable*)_d->method_hash_table, GINT_TO_POINTER(_method))))

#define CHECK_EVENT(_e) {if (0 == _e) { \
nyx_error ("invalid handle"); \
Expand All @@ -56,7 +60,7 @@
return NYX_ERROR_WRONG_DEVICE_TYPE; \
}}
#define nyx_execute_return_function(_f,_t,_m,_h,...) \
nyx_device_t* d = (nyx_device_t*)_h;\
nyx_device_t* d = (nyx_device_t*)_h; \
CHECK_DEVICE(d); \
CHECK_DEVICE_TYPE(d, NYX_DEVICE_##_t); \
nyx_##_f##_function_t _f_ptr = \
Expand Down

0 comments on commit 10c58ad

Please sign in to comment.