common: Fix module_hash hash operations from direct to string 38/316838/1
authorYoungjae Cho <y0.cho@samsung.com>
Thu, 5 Dec 2024 06:57:23 +0000 (15:57 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Wed, 18 Dec 2024 02:14:02 +0000 (11:14 +0900)
It matters when it comes to unittest. The unittest code below may
cause an unintended result.

  > char *library_name = g_strdup_printf("libhal-backend-%s-user-specific.so",
  >         info.backend_module_name_);
  > int ret = hal_common_get_backend_with_library_name(info.module_,
            (void **)&backend_module_data,
            library_name);

Over the instantiated testcases, the g_strdup_printf() sometimes returns
same address containing different string. In this case, if the hash and
equal function are g_direct_hash() and g_direct_equal(), then it tests
those different string as equal because both strings are held by the
same address. Therefore, it is not enough to compare the starting
address but needs to compare the entire string.

Change-Id: Ifecbac1db3d03d61137e31b74e356ba0370c345d
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
src/hal-api-conf.c

index 8e57d8a3e2ecfff1134396f386197135067779ba..5aff07a878f2ad6438e88f157c3ea9b754234096 100644 (file)
@@ -153,7 +153,7 @@ int _hal_api_conf_init(void)
        if (_usage_count++ > 0)
                return 0;
 
-       _module_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, _destroy_module_info);
+       _module_hash = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, _destroy_module_info);
 
        return 0;
 }