Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Correct the handling of null method_hash_table pointers

Change-Id: I4a5e5a3e7d0f0320ddd7eab3125e64a1b794dbc6
  • Loading branch information...
commit 10c58ad68657a3f0d13aebf4c2f008fb8ac5f614 1 parent 95d8c16
@DrWEbOS DrWEbOS authored Gerrit Code Review committed
Showing with 34 additions and 18 deletions.
  1. +27 −15 src/device/nyx_device_impl.c
  2. +7 −3 src/device/nyx_device_impl.h
View
42 src/device/nyx_device_impl.c
@@ -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.
@@ -418,10 +424,12 @@ 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)
@@ -429,21 +437,25 @@ nyx_error_t nyx_device_get_report_rate(nyx_device_handle_t handle, nyx_report_ra
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)
View
10 src/device/nyx_device_impl.h
@@ -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"); \
@@ -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 = \
Please sign in to comment.
Something went wrong with that request. Please try again.