Skip to content

Commit d01c9e2

Browse files
Update test.c
1 parent a6b9dbf commit d01c9e2

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

code/logic/test.c

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -84,41 +84,42 @@ int fossil_pizza_add_suite(fossil_pizza_engine_t* engine, fossil_pizza_suite_t s
8484

8585
// --- TI Metadata Initialization ---
8686
suite.meta.timestamp = time(NULL);
87-
88-
if (!suite.meta.origin_device_id)
89-
suite.meta.origin_device_id = "unknown";
90-
91-
if (!suite.meta.author)
92-
suite.meta.author = "anonymous";
87+
if (!suite.meta.origin_device_id) suite.meta.origin_device_id = "unknown";
88+
if (!suite.meta.author) suite.meta.author = "anonymous";
9389

9490
suite.meta.trust_score = 0.0;
95-
suite.meta.confidence = 0.0;
96-
suite.meta.immutable = false;
91+
suite.meta.confidence = 0.0;
92+
suite.meta.immutable = false;
9793

9894
// Previous hash from engine
99-
suite.meta.prev_hash = engine->meta.hash ? engine->meta.hash : NULL;
95+
char* prev_hash = engine->meta.hash ? engine->meta.hash : "";
96+
suite.meta.prev_hash = prev_hash;
10097

10198
// Prepare input string
10299
char input_buf[1000] = {0};
103-
if (pizza_io_cstr_append(input_buf, sizeof(input_buf), suite.suite_name) != 0 ||
104-
pizza_io_cstr_append(input_buf, sizeof(input_buf), suite.meta.author) != 0 ||
105-
pizza_io_cstr_append(input_buf, sizeof(input_buf), suite.meta.origin_device_id) != 0) {
106-
return FOSSIL_PIZZA_FAILURE; // Overflow
100+
if (!pizza_io_cstr_append(input_buf, sizeof(input_buf), suite.suite_name) ||
101+
!pizza_io_cstr_append(input_buf, sizeof(input_buf), suite.meta.author) ||
102+
!pizza_io_cstr_append(input_buf, sizeof(input_buf), suite.meta.origin_device_id)) {
103+
return FOSSIL_PIZZA_FAILURE;
107104
}
108105

109106
// Compute hash
110107
uint8_t hash_raw[32];
111-
char* prev_hash = (char*)suite.meta.prev_hash;
112-
fossil_pizza_hash(input_buf, prev_hash ? prev_hash : "", hash_raw);
108+
fossil_pizza_hash(input_buf, prev_hash, hash_raw);
113109

114-
// Convert hash to hex string
110+
// Convert to hex
115111
char* hash_hex = pizza_sys_memory_alloc(65);
116112
if (!hash_hex) return FOSSIL_PIZZA_FAILURE;
117-
for (int i = 0; i < 32; ++i)
118-
snprintf(&hash_hex[i * 2], 3, "%02x", hash_raw[i]);
113+
114+
static const char hex[] = "0123456789abcdef";
115+
for (int i = 0; i < 32; ++i) {
116+
hash_hex[i * 2] = hex[(hash_raw[i] >> 4) & 0xF];
117+
hash_hex[i * 2 + 1] = hex[hash_raw[i] & 0xF];
118+
}
119+
hash_hex[64] = '\0';
119120
suite.meta.hash = hash_hex;
120121

121-
// Add suite to engine
122+
// Add to engine
122123
engine->suites[engine->count++] = suite;
123124
return FOSSIL_PIZZA_SUCCESS;
124125
}

0 commit comments

Comments
 (0)