@@ -178,45 +178,47 @@ TEST(MutableFuncRegistry, Create) {
178178
179179 for (unsigned int rem = 0 ; rem < kTvmAverageFuncEntrySizeBytes ; rem++) {
180180 // test_function name will be used to test overfilling.
181- char test_function_name[kTvmAverageFunctionNameStrlenBytes + 2 + rem];
181+ auto test_function_name =
182+ std::make_unique<char []>(kTvmAverageFunctionNameStrlenBytes + 2 + rem);
182183 TVMMutableFuncRegistry reg;
183184 memset (mem_buffer, 0 , sizeof (mem_buffer));
184185 EXPECT_EQ (kTvmErrorNoError , TVMMutableFuncRegistry_Create (
185186 ®, mem_buffer, kTvmAverageFuncEntrySizeBytes * 2 + rem));
186187
187- snprintf_truncate (test_function_name, kTvmAverageFunctionNameStrlenBytes + 1 ,
188+ snprintf_truncate (test_function_name. get () , kTvmAverageFunctionNameStrlenBytes + 1 ,
188189 function_name_chars);
189190
190191 // Add function #1, and verify it can be retrieved.
191- EXPECT_EQ (kTvmErrorNoError ,
192- TVMMutableFuncRegistry_Set (®, test_function_name, TestFunctionHandle (0x01 ), 0 ));
192+ EXPECT_EQ (kTvmErrorNoError , TVMMutableFuncRegistry_Set (®, test_function_name. get (),
193+ TestFunctionHandle (0x01 ), 0 ));
193194
194195 tvm_function_index_t func_index = 100 ;
195196 EXPECT_EQ (kTvmErrorNoError ,
196- TVMFuncRegistry_Lookup (®.registry , test_function_name, &func_index));
197+ TVMFuncRegistry_Lookup (®.registry , test_function_name. get () , &func_index));
197198 EXPECT_EQ (func_index, 0 );
198199
199200 TVMBackendPackedCFunc func = NULL ;
200201 EXPECT_EQ (kTvmErrorNoError , TVMFuncRegistry_GetByIndex (®.registry , func_index, &func));
201202 EXPECT_EQ (func, TestFunctionHandle (0x01 ));
202203
203204 // Ensure that overfilling `names` by 1 char is not allowed.
204- snprintf_truncate (test_function_name, kTvmAverageFunctionNameStrlenBytes + rem + 2 ,
205+ snprintf_truncate (test_function_name. get () , kTvmAverageFunctionNameStrlenBytes + rem + 2 ,
205206 function_name_chars + 1 );
206207
207- EXPECT_EQ (kTvmErrorFunctionRegistryFull ,
208- TVMMutableFuncRegistry_Set (®, test_function_name, TestFunctionHandle (0x02 ), 0 ));
208+ EXPECT_EQ (
209+ kTvmErrorFunctionRegistryFull ,
210+ TVMMutableFuncRegistry_Set (®, test_function_name.get (), TestFunctionHandle (0x02 ), 0 ));
209211 EXPECT_EQ (kTvmErrorFunctionNameNotFound ,
210- TVMFuncRegistry_Lookup (®.registry , test_function_name, &func_index));
212+ TVMFuncRegistry_Lookup (®.registry , test_function_name. get () , &func_index));
211213
212214 // Add function #2, with intentionally short (by 2 char) name. Verify it can be retrieved.
213- snprintf_truncate (test_function_name, kTvmAverageFunctionNameStrlenBytes - 2 + 1 ,
215+ snprintf_truncate (test_function_name. get () , kTvmAverageFunctionNameStrlenBytes - 2 + 1 ,
214216 function_name_chars + 1 );
215- EXPECT_EQ (kTvmErrorNoError ,
216- TVMMutableFuncRegistry_Set (®, test_function_name, TestFunctionHandle (0x02 ), 0 ));
217+ EXPECT_EQ (kTvmErrorNoError , TVMMutableFuncRegistry_Set (®, test_function_name. get (),
218+ TestFunctionHandle (0x02 ), 0 ));
217219
218220 EXPECT_EQ (kTvmErrorNoError ,
219- TVMFuncRegistry_Lookup (®.registry , test_function_name, &func_index));
221+ TVMFuncRegistry_Lookup (®.registry , test_function_name. get () , &func_index));
220222 EXPECT_EQ (func_index, 1 );
221223
222224 func = NULL ;
@@ -226,7 +228,8 @@ TEST(MutableFuncRegistry, Create) {
226228 // Try adding another function, which should fail due to lack of function pointers.
227229 test_function_name[0 ] = ' a' ;
228230 test_function_name[1 ] = 0 ;
229- EXPECT_EQ (kTvmErrorFunctionRegistryFull ,
230- TVMMutableFuncRegistry_Set (®, test_function_name, TestFunctionHandle (0x03 ), 0 ));
231+ EXPECT_EQ (
232+ kTvmErrorFunctionRegistryFull ,
233+ TVMMutableFuncRegistry_Set (®, test_function_name.get (), TestFunctionHandle (0x03 ), 0 ));
231234 }
232- }
235+ }
0 commit comments