@@ -125,6 +125,8 @@ int fossil_pizza_add_suite(fossil_pizza_engine_t* engine, fossil_pizza_suite_t s
125125}
126126
127127// --- Add Case ---
128+ #define FOSSIL_PIZZA_HASH_HEX_LEN 65
129+
128130int fossil_pizza_add_case (fossil_pizza_suite_t * suite , fossil_pizza_case_t test_case ) {
129131 if (!suite ) return FOSSIL_PIZZA_FAILURE ;
130132
@@ -139,13 +141,8 @@ int fossil_pizza_add_case(fossil_pizza_suite_t* suite, fossil_pizza_case_t test_
139141
140142 // --- TI Metadata Initialization ---
141143 test_case .meta .timestamp = time (NULL );
142-
143- if (!test_case .meta .origin_device_id )
144- test_case .meta .origin_device_id = "unknown" ;
145-
146- if (!test_case .meta .author )
147- test_case .meta .author = "anonymous" ;
148-
144+ test_case .meta .origin_device_id = test_case .meta .origin_device_id ? test_case .meta .origin_device_id : "unknown" ;
145+ test_case .meta .author = test_case .meta .author ? test_case .meta .author : "anonymous" ;
149146 test_case .meta .trust_score = 0.0 ;
150147 test_case .meta .confidence = 0.0 ;
151148 test_case .meta .immutable = false;
@@ -155,22 +152,24 @@ int fossil_pizza_add_case(fossil_pizza_suite_t* suite, fossil_pizza_case_t test_
155152
156153 // Prepare input string
157154 char input_buf [1000 ] = {0 };
158- if (pizza_io_cstr_append (input_buf , sizeof (input_buf ), test_case .name ) != 0 ||
159- pizza_io_cstr_append (input_buf , sizeof (input_buf ), test_case .criteria ) != 0 ||
160- pizza_io_cstr_append (input_buf , sizeof (input_buf ), test_case .meta .author ) != 0 ) {
155+ if (! pizza_io_cstr_append (input_buf , sizeof (input_buf ), test_case .name ) ||
156+ ! pizza_io_cstr_append (input_buf , sizeof (input_buf ), test_case .criteria ) ||
157+ ! pizza_io_cstr_append (input_buf , sizeof (input_buf ), test_case .meta .author )) {
161158 return FOSSIL_PIZZA_FAILURE ; // Overflow occurred
162159 }
163160
164161 // Compute hash
165162 uint8_t hash_raw [32 ];
166- char * prev_hash = ( char * ) test_case .meta .prev_hash ;
167- fossil_pizza_hash (input_buf , prev_hash ? prev_hash : "" , hash_raw );
163+ char * prev_hash = test_case .meta .prev_hash ? test_case . meta . prev_hash : "" ;
164+ fossil_pizza_hash (input_buf , prev_hash , hash_raw );
168165
169- // Convert to hex string
170- char * hash_hex = pizza_sys_memory_alloc (65 );
166+ // Convert hash to hex string
167+ char * hash_hex = pizza_sys_memory_alloc (FOSSIL_PIZZA_HASH_HEX_LEN );
171168 if (!hash_hex ) return FOSSIL_PIZZA_FAILURE ;
169+
172170 for (int i = 0 ; i < 32 ; ++ i )
173- snprintf (& hash_hex [i * 2 ], 3 , "%02x" , hash_raw [i ]);
171+ sprintf (& hash_hex [i * 2 ], "%02x" , hash_raw [i ]);
172+
174173 test_case .meta .hash = hash_hex ;
175174
176175 // Add test case to suite
0 commit comments