-
Notifications
You must be signed in to change notification settings - Fork 12k
examples : sprintf -> snprintf #8434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
examples/gguf-hash/gguf-hash.cpp
Outdated
@@ -347,7 +347,7 @@ static hash_exit_code_t gguf_hash(const hash_params & hash_params) { | |||
char hex_result[17]; | |||
for (int offset = 0; offset < 8; offset++) { | |||
unsigned int shift_bits_by = (8 * (8 - offset - 1)); | |||
sprintf( ( hex_result + (2*offset)), "%02x", (unsigned char) (hash >> shift_bits_by)&0xff); | |||
snprintf( ( hex_result + (2*offset)), 17, "%02x", (unsigned char) (hash >> shift_bits_by)&0xff); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
snprintf( ( hex_result + (2*offset)), 17, "%02x", (unsigned char) (hash >> shift_bits_by)&0xff); | |
snprintf( ( hex_result + (2*offset)), sizeof(hex_result) - (2*offset), "%02x", (unsigned char) (hash >> shift_bits_by)&0xff); |
examples/gguf-hash/gguf-hash.cpp
Outdated
@@ -384,7 +384,7 @@ static hash_exit_code_t gguf_hash(const hash_params & hash_params) { | |||
|
|||
char hex_result[41] = {0}; | |||
for (int offset = 0; offset < 20; offset++) { | |||
sprintf( ( hex_result + (2*offset)), "%02x", result[offset]&0xff); | |||
snprintf( ( hex_result + (2*offset)), 41, "%02x", result[offset]&0xff); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
snprintf( ( hex_result + (2*offset)), 41, "%02x", result[offset]&0xff); | |
snprintf( ( hex_result + (2*offset)), sizeof(hex_result) - (2*offset), "%02x", result[offset]&0xff); |
examples/gguf-hash/gguf-hash.cpp
Outdated
@@ -421,7 +421,7 @@ static hash_exit_code_t gguf_hash(const hash_params & hash_params) { | |||
|
|||
char hex_result[SHA256_DIGEST_SIZE * 2 + 1] = {0}; | |||
for (int offset = 0; offset < SHA256_DIGEST_SIZE; offset++) { | |||
sprintf( ( hex_result + (2*offset)), "%02x", result[offset]&0xff); | |||
snprintf( ( hex_result + (2*offset)), SHA256_DIGEST_SIZE * 2 + 1, "%02x", result[offset]&0xff); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
snprintf( ( hex_result + (2*offset)), SHA256_DIGEST_SIZE * 2 + 1, "%02x", result[offset]&0xff); | |
snprintf( ( hex_result + (2*offset)), sizeof(hex_result) - (2*offset), "%02x", result[offset]&0xff); |
examples/gguf-hash/gguf-hash.cpp
Outdated
@@ -460,7 +460,7 @@ static hash_exit_code_t gguf_hash(const hash_params & hash_params) { | |||
char hex_result[17]; | |||
for (int offset = 0; offset < 8; offset++) { | |||
unsigned int shift_bits_by = (8 * (8 - offset - 1)); | |||
sprintf( ( hex_result + (2*offset)), "%02x", (unsigned char) (hash >> shift_bits_by)&0xff); | |||
snprintf( ( hex_result + (2*offset)), 17, "%02x", (unsigned char) (hash >> shift_bits_by)&0xff); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
snprintf( ( hex_result + (2*offset)), 17, "%02x", (unsigned char) (hash >> shift_bits_by)&0xff); | |
snprintf( ( hex_result + (2*offset)), sizeof(hex_result) - (2*offset), "%02x", (unsigned char) (hash >> shift_bits_by)&0xff); |
examples/gguf-hash/gguf-hash.cpp
Outdated
@@ -490,7 +490,7 @@ static hash_exit_code_t gguf_hash(const hash_params & hash_params) { | |||
|
|||
char hex_result[41]; | |||
for (int offset = 0; offset < 20; offset++) { | |||
sprintf( ( hex_result + (2*offset)), "%02x", result[offset]&0xff); | |||
snprintf( ( hex_result + (2*offset)), 41, "%02x", result[offset]&0xff); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
snprintf( ( hex_result + (2*offset)), 41, "%02x", result[offset]&0xff); | |
snprintf( ( hex_result + (2*offset)), sizeof(hex_result) - (2*offset), "%02x", result[offset]&0xff); |
examples/gguf-hash/gguf-hash.cpp
Outdated
@@ -520,7 +520,7 @@ static hash_exit_code_t gguf_hash(const hash_params & hash_params) { | |||
|
|||
char hex_result[SHA256_DIGEST_SIZE * 2 + 1] = {0}; | |||
for (int offset = 0; offset < SHA256_DIGEST_SIZE; offset++) { | |||
sprintf( ( hex_result + (2*offset)), "%02x", result[offset]&0xff); | |||
snprintf( ( hex_result + (2*offset)), SHA256_DIGEST_SIZE * 2 + 1, "%02x", result[offset]&0xff); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
snprintf( ( hex_result + (2*offset)), SHA256_DIGEST_SIZE * 2 + 1, "%02x", result[offset]&0xff); | |
snprintf( ( hex_result + (2*offset)), sizeof(hex_result) - (2*offset), "%02x", result[offset]&0xff); |
* examples : sprintf -> snprintf ggml-ci * examples : use sizeof() instead of hardcoded constants
* examples : sprintf -> snprintf ggml-ci * examples : use sizeof() instead of hardcoded constants
* examples : sprintf -> snprintf ggml-ci * examples : use sizeof() instead of hardcoded constants
Fix compile warnings