common: Fix module_hash hash operations from direct to string 76/315876/6
authorYoungjae Cho <y0.cho@samsung.com>
Thu, 5 Dec 2024 06:57:23 +0000 (15:57 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Fri, 10 Jan 2025 03:51:00 +0000 (03:51 +0000)
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 fc00bf3cb5a7b86eb31e433bf9619d38f0ff5a0b..e373ef1bd04c4a623877635565f58a4607a1516c 100644 (file)
@@ -154,7 +154,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;
 }