@@ -347,7 +347,7 @@ static hash_exit_code_t gguf_hash(const hash_params & hash_params) {
347
347
char hex_result[17 ];
348
348
for (int offset = 0 ; offset < 8 ; offset++) {
349
349
unsigned int shift_bits_by = (8 * (8 - offset - 1 ));
350
- sprintf ( ( hex_result + (2 *offset)), " %02x" , (unsigned char ) (hash >> shift_bits_by)&0xff );
350
+ snprintf ( ( hex_result + (2 *offset)), sizeof (hex_result) - ( 2 *offset ), " %02x" , (unsigned char ) (hash >> shift_bits_by)&0xff );
351
351
}
352
352
353
353
if (hash_params.manifest_is_usable ) {
@@ -384,7 +384,7 @@ static hash_exit_code_t gguf_hash(const hash_params & hash_params) {
384
384
385
385
char hex_result[41 ] = {0 };
386
386
for (int offset = 0 ; offset < 20 ; offset++) {
387
- sprintf ( ( hex_result + (2 *offset)), " %02x" , result[offset]&0xff );
387
+ snprintf ( ( hex_result + (2 *offset)), sizeof (hex_result) - ( 2 *offset ), " %02x" , result[offset]&0xff );
388
388
}
389
389
390
390
if (hash_params.manifest_is_usable ) {
@@ -421,7 +421,7 @@ static hash_exit_code_t gguf_hash(const hash_params & hash_params) {
421
421
422
422
char hex_result[SHA256_DIGEST_SIZE * 2 + 1 ] = {0 };
423
423
for (int offset = 0 ; offset < SHA256_DIGEST_SIZE; offset++) {
424
- sprintf ( ( hex_result + (2 *offset)), " %02x" , result[offset]&0xff );
424
+ snprintf ( ( hex_result + (2 *offset)), sizeof (hex_result) - ( 2 *offset ), " %02x" , result[offset]&0xff );
425
425
}
426
426
427
427
if (hash_params.manifest_is_usable ) {
@@ -460,7 +460,7 @@ static hash_exit_code_t gguf_hash(const hash_params & hash_params) {
460
460
char hex_result[17 ];
461
461
for (int offset = 0 ; offset < 8 ; offset++) {
462
462
unsigned int shift_bits_by = (8 * (8 - offset - 1 ));
463
- sprintf ( ( hex_result + (2 *offset)), " %02x" , (unsigned char ) (hash >> shift_bits_by)&0xff );
463
+ snprintf ( ( hex_result + (2 *offset)), sizeof (hex_result) - ( 2 *offset ), " %02x" , (unsigned char ) (hash >> shift_bits_by)&0xff );
464
464
}
465
465
466
466
if (hash_params.manifest_is_usable ) {
@@ -490,7 +490,7 @@ static hash_exit_code_t gguf_hash(const hash_params & hash_params) {
490
490
491
491
char hex_result[41 ];
492
492
for (int offset = 0 ; offset < 20 ; offset++) {
493
- sprintf ( ( hex_result + (2 *offset)), " %02x" , result[offset]&0xff );
493
+ snprintf ( ( hex_result + (2 *offset)), sizeof (hex_result) - ( 2 *offset ), " %02x" , result[offset]&0xff );
494
494
}
495
495
496
496
if (hash_params.manifest_is_usable ) {
@@ -520,7 +520,7 @@ static hash_exit_code_t gguf_hash(const hash_params & hash_params) {
520
520
521
521
char hex_result[SHA256_DIGEST_SIZE * 2 + 1 ] = {0 };
522
522
for (int offset = 0 ; offset < SHA256_DIGEST_SIZE; offset++) {
523
- sprintf ( ( hex_result + (2 *offset)), " %02x" , result[offset]&0xff );
523
+ snprintf ( ( hex_result + (2 *offset)), sizeof (hex_result) - ( 2 *offset ), " %02x" , result[offset]&0xff );
524
524
}
525
525
526
526
if (hash_params.manifest_is_usable ) {
@@ -552,7 +552,7 @@ static hash_exit_code_t gguf_hash(const hash_params & hash_params) {
552
552
generate_uuidv5 (result, uuid);
553
553
554
554
char string_buffer[37 ] = {0 };
555
- sprintf (string_buffer, " %02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" ,
555
+ snprintf (string_buffer, sizeof (string_buffer) , " %02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" ,
556
556
uuid[0 ], uuid[1 ], uuid[2 ], uuid[3 ],
557
557
uuid[4 ], uuid[5 ], uuid[6 ], uuid[7 ],
558
558
uuid[8 ], uuid[9 ], uuid[10 ], uuid[11 ],
0 commit comments