Skip to content

Commit

Permalink
fix: format specifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierChanth committed Mar 5, 2025
1 parent 2117a22 commit 07c0318
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 74 deletions.
1 change: 1 addition & 0 deletions cmake/package_util.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ function(build_atsdk_package)
)

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "LINKING PRIVATE HEADERS FOR DEBUG MODE")
target_include_directories(
${PROJECT_NAME}
PUBLIC $<BUILD_INTERFACE:${arg_PACKAGE_DIR}/src>
Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ release_c_flags := "-std=c99 -Wno-error"

# SETUP COMMANDS

setup: configure-test-all
setup: build-test-all
[ -f "$PWD/compile_commands.json" ] && rm $PWD/compile_commands.json || true
ln -s {{test_dir}}/compile_commands.json $PWD/
[ -f "$PWD/tests/compile_commands.json" ] && rm $PWD/tests/compile_commands.json || true
Expand Down
2 changes: 1 addition & 1 deletion packages/atclient/src/atkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ int atclient_atkey_to_string(const atclient_atkey *atkey, char **atkeystr) {

if (index_pos != atkey_str_size - 1) {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_WARN,
"index_pos != atkey_str_size - 1 (%d != %d - 1). The predicted `atkey_str_size` variable was not "
"index_pos != atkey_str_size - 1 (%zu != %zu - 1). The predicted `atkey_str_size` variable was not "
"evaluated correctly.\n",
index_pos, atkey_str_size);
}
Expand Down
18 changes: 9 additions & 9 deletions packages/atclient/src/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ int atclient_connection_connect(atclient_connection *ctx, const char *host, cons
size_t n1, n2;
ret = atclient_tls_socket_read(&ctx->_socket, &buf1, &n1, atclient_socket_read_until_char('@'));
if (ret != 0) {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to read from the connection\n", ret);
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to read from the connection\n");
goto exit;
}
free(buf1);
Expand All @@ -118,7 +118,7 @@ int atclient_connection_connect(atclient_connection *ctx, const char *host, cons

ret = atclient_tls_socket_read(&ctx->_socket, &buf2, &n2, atclient_socket_read_until_char('@'));
if (ret != 0) {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to read from the connection\n", ret);
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to read from the connection\n");
goto exit;
}
free(buf2);
Expand Down Expand Up @@ -210,7 +210,7 @@ int atclient_connection_write(atclient_connection *ctx, const unsigned char *val
if (valuecopy != NULL) {
memcpy(valuecopy, value, value_len);
atlogger_fix_stdout_buffer((char *)valuecopy, value_len);
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "\t%sSENT: %s\"%.*s\"%s\n", BBLU, HCYN, value_len, valuecopy,
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "\t%sSENT: %s\"%.*s\"%s\n", BBLU, HCYN, (int)value_len, valuecopy,
ATCLIENT_RESET);
free(valuecopy);
} else {
Expand Down Expand Up @@ -313,8 +313,8 @@ int atclient_connection_send(atclient_connection *ctx, const unsigned char *src,
if ((srccopy = malloc(sizeof(unsigned char) * src_len)) != NULL) {
memcpy(srccopy, src, src_len);
atlogger_fix_stdout_buffer((char *)srccopy, src_len);
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "\t%sSENT: %s\"%.*s\"%s\n", BBLU, HCYN, strlen((char *)srccopy),
srccopy, ATCLIENT_RESET);
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "\t%sSENT: %s\"%.*s\"%s\n", BBLU, HCYN,
(int)strlen((char *)srccopy), srccopy, ATCLIENT_RESET);
free(srccopy);
} else {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR,
Expand Down Expand Up @@ -387,7 +387,7 @@ int atclient_connection_send(atclient_connection *ctx, const unsigned char *src,
size_t read_n;
ret = atclient_tls_socket_read(&ctx->_socket, &read_buf, &read_n, atclient_socket_read_until_char('\n'));
if (ret != 0) {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to read from the connection\n", ret);
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to read from the connection\n");
goto exit;
}

Expand Down Expand Up @@ -441,7 +441,7 @@ int atclient_connection_send(atclient_connection *ctx, const unsigned char *src,
if ((recvcopy = malloc(sizeof(unsigned char) * *recv_len)) != NULL) {
memcpy(recvcopy, recv, *recv_len);
atlogger_fix_stdout_buffer((char *)recvcopy, *recv_len);
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "\t%sRECV: %s\"%.*s\"%s\n", BMAG, HMAG, *recv_len, recvcopy,
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "\t%sRECV: %s\"%.*s\"%s\n", BMAG, HMAG, (int)*recv_len, recvcopy,
ATCLIENT_RESET);
free(recvcopy);
} else {
Expand Down Expand Up @@ -576,7 +576,7 @@ int atclient_connection_read(atclient_connection *ctx, unsigned char **value, si
size_t read_n;
ret = atclient_tls_socket_read(&ctx->_socket, &read_buf, &read_n, atclient_socket_read_until_char('\n'));
if (ret != 0) {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to read from the connection\n", ret);
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to read from the connection\n");
goto exit;
}
size_t read_i = 0; // will store where the start of `<type>:` is (if happy path)
Expand All @@ -602,7 +602,7 @@ int atclient_connection_read(atclient_connection *ctx, unsigned char **value, si
* 5. Print debug log
*/
if (atlogger_get_logging_level() >= ATLOGGER_LOGGING_LEVEL_DEBUG) {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "\t%sRECV: %s\"%.*s\"%s\n", BMAG, HMAG, *value_len, *value,
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "\t%sRECV: %s\"%.*s\"%s\n", BMAG, HMAG, (int)*value_len, *value,
ATCLIENT_RESET);
}

Expand Down
7 changes: 3 additions & 4 deletions packages/atclient/src/monitor.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "atclient/monitor.h"
#include "atclient/atclient.h"
#include "atclient/atclient_utils.h"
#include "atclient/atnotification.h"
#include "atclient/connection.h"
#include "atclient/constants.h"
Expand Down Expand Up @@ -159,7 +158,7 @@ int atclient_monitor_read(atclient *monitor_conn, atclient *atclient, atclient_m
}
// no longer need to free buffer, memory is owned by message->atserver_message

atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "\t%sRECV: %s\"%.*s\"%s\n", BMAG, HMAG, buffer_len, buffer,
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_DEBUG, "\t%sRECV: %s\"%.*s\"%s\n", BMAG, HMAG, (int)buffer_len, buffer,
ATCLIENT_RESET);

ret = populate_monitor_message(message);
Expand Down Expand Up @@ -243,7 +242,7 @@ int populate_monitor_message(atclient_monitor_message *message) {
}
break;
}
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Unknown token type: %.*s\n", token_len, token);
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Unknown token type: %.*s\n", (int)token_len, token);
message->type = ATCLIENT_MONITOR_MESSAGE_TYPE_NONE;
return 2;
}
Expand Down Expand Up @@ -390,7 +389,7 @@ int decrypt_notification(atclient *atclient, atclient_atnotification *notificati

if (ivlen != ATCHOPS_IV_BUFFER_SIZE) {
ret = 1;
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Invalid iv length was decoded. Expected %d but got %d\n",
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Invalid iv length was decoded. Expected %d but got %zu\n",
ATCHOPS_IV_BUFFER_SIZE, ivlen);
goto exit;
}
Expand Down
9 changes: 5 additions & 4 deletions packages/atclient/src/notify.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,9 @@ static size_t calculate_cmd_size(const atclient_notify_params *params, const siz
cmdsize += strlen(":ttln:") + atclient_string_utils_long_strlen(params->notification_expiry); // :$ttln
}

if(atclient_notify_params_is_should_encrypt_initialized(params)) {
cmdsize += strlen(":isEncrypted:") + (params->should_encrypt ? strlen("true") : strlen("false")); // :isEncrypted:true | :isEncrypted:false
if (atclient_notify_params_is_should_encrypt_initialized(params)) {
cmdsize += strlen(":isEncrypted:") +
(params->should_encrypt ? strlen("true") : strlen("false")); // :isEncrypted:true | :isEncrypted:false
}

if (atclient_notify_params_is_atkey_initialized(params)) {
Expand Down Expand Up @@ -290,7 +291,7 @@ static int generate_cmd(const atclient_notify_params *params, const char *cmdval
cmdsize = calculate_cmd_size(params, cmdvaluelen, &atkeylen, &metadatastrlen);
if (cmdsize <= 0) {
res = 1;
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "calculate_cmd_size failed with code %d\n", cmdsize);
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "calculate_cmd_size failed with code %zu\n", cmdsize);
goto exit;
}

Expand Down Expand Up @@ -341,7 +342,7 @@ static int generate_cmd(const atclient_notify_params *params, const char *cmdval
off += strlen(":ttln:") + atclient_string_utils_long_strlen(params->notification_expiry);
}

if(atclient_notify_params_is_should_encrypt_initialized(params)) {
if (atclient_notify_params_is_should_encrypt_initialized(params)) {
const char *isEncryptedBool = params->should_encrypt ? "true" : "false";
snprintf(cmd + off, cmdsize - off, ":isEncrypted:%s", isEncryptedBool);
off += strlen(":isEncrypted:") + strlen(isEncryptedBool);
Expand Down
3 changes: 2 additions & 1 deletion packages/atclient/tests/test_atkey_metadata.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "atclient/metadata.h"
#include "atlogger/atlogger.h"
#include <inttypes.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -142,7 +143,7 @@ static int test_atkey_metadata_from_jsonstr() {

if (metadata.ttl != 86400) {
ret = 1;
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "metadata.ttl != 86400: %ld\n", metadata.ttl);
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "metadata.ttl != 86400: %" PRIu64 "\n", metadata.ttl);
goto exit;
}

Expand Down
72 changes: 36 additions & 36 deletions packages/atclient/tests/test_atserver_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ int main() {
return ret;
}

#define expect_uint(TEST_TAG, EXP, ACT) \
#define expect_uint(TEST_TAG, EXP, FMT, ACT) \
if (EXP != ACT) { \
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "%s: incorrect value (expected: %u, actual: %u)\n", TEST_TAG, EXP, \
ACT); \
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "%s: incorrect value (expected: %u, actual: %" FMT ")\n", \
TEST_TAG, EXP, ACT); \
return 1; \
}

Expand All @@ -59,10 +59,10 @@ uint8_t test_1a_long_prompt() {
return 1;
}

expect_uint("prompt len", 8, message.prompt_len);
expect_uint("token len", 5, message.token_len);
expect_uint("body len", 3, atserver_message_get_body_len(message));
expect_uint("len", 16, message.len);
expect_uint("prompt len", 8, "u", message.prompt_len);
expect_uint("token len", 5, "u", message.token_len);
expect_uint("body len", 3, "zu", atserver_message_get_body_len(message));
expect_uint("len", 16, "zu", message.len);

return 0;
}
Expand All @@ -80,10 +80,10 @@ uint8_t test_1b_short_prompt() {
return 1;
}

expect_uint("prompt len", 1, message.prompt_len);
expect_uint("token len", 5, message.token_len);
expect_uint("body len", 3, atserver_message_get_body_len(message));
expect_uint("len", 9, message.len);
expect_uint("prompt len", 1, "u", message.prompt_len);
expect_uint("token len", 5, "u", message.token_len);
expect_uint("body len", 3, "zu", atserver_message_get_body_len(message));
expect_uint("len", 9, "zu", message.len);

return 0;
}
Expand All @@ -101,10 +101,10 @@ uint8_t test_1c_no_prompt() {
return 1;
}

expect_uint("prompt len", 0, message.prompt_len);
expect_uint("token len", 5, message.token_len);
expect_uint("body len", 3, atserver_message_get_body_len(message));
expect_uint("len", 8, message.len);
expect_uint("prompt len", 0, "u", message.prompt_len);
expect_uint("token len", 5, "u", message.token_len);
expect_uint("body len", 3, "zu", atserver_message_get_body_len(message));
expect_uint("len", 8, "zu", message.len);

return 0;
}
Expand All @@ -122,10 +122,10 @@ uint8_t test_2a_no_token() {
return 1;
}

expect_uint("prompt len", 0, message.prompt_len);
expect_uint("token len", 0, message.token_len);
expect_uint("body len", 0, atserver_message_get_body_len(message));
expect_uint("len", 0, message.len);
expect_uint("prompt len", 0, "u", message.prompt_len);
expect_uint("token len", 0, "u", message.token_len);
expect_uint("body len", 0, "zu", atserver_message_get_body_len(message));
expect_uint("len", 0, "zu", message.len);

return 0;
}
Expand All @@ -143,10 +143,10 @@ uint8_t test_3a_no_body() {
return 1;
}

expect_uint("prompt len", 8, message.prompt_len);
expect_uint("token len", 5, message.token_len);
expect_uint("body len", 0, atserver_message_get_body_len(message));
expect_uint("len", 13, message.len);
expect_uint("prompt len", 8, "u", message.prompt_len);
expect_uint("token len", 5, "u", message.token_len);
expect_uint("body len", 0, "zu", atserver_message_get_body_len(message));
expect_uint("len", 13, "zu", message.len);

return 0;
}
Expand All @@ -162,10 +162,10 @@ uint8_t test_4a_empty_message() {
return 1;
}

expect_uint("prompt len", 0, message.prompt_len);
expect_uint("token len", 0, message.token_len);
expect_uint("body len", 0, atserver_message_get_body_len(message));
expect_uint("len", 0, message.len);
expect_uint("prompt len", 0, "u", message.prompt_len);
expect_uint("token len", 0, "u", message.token_len);
expect_uint("body len", 0, "zu", atserver_message_get_body_len(message));
expect_uint("len", 0, "zu", message.len);

return 0;
}
Expand All @@ -189,10 +189,10 @@ uint8_t test_5a_heap() {
return 1;
}

expect_uint("prompt len", 8, message.prompt_len);
expect_uint("token len", 5, message.token_len);
expect_uint("body len", 3, atserver_message_get_body_len(message));
expect_uint("len", 16, message.len);
expect_uint("prompt len", 8, "u", message.prompt_len);
expect_uint("token len", 5, "u", message.token_len);
expect_uint("body len", 3, "zu", atserver_message_get_body_len(message));
expect_uint("len", 16, "zu", message.len);

message.buffer[0] = 'H';
if (strncmp(heap_buffer, "Hfoobar@data:baz", len) != 0) {
Expand All @@ -204,7 +204,7 @@ uint8_t test_5a_heap() {
atserver_message_free(&message);
if (message.buffer != NULL) {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR,
"message.buffer is expected to be NULL after free but it isn't: %zu\n", message.buffer);
"message.buffer is expected to be NULL after free but it isn't: %s\n", message.buffer);
return 1;
}

Expand Down Expand Up @@ -232,10 +232,10 @@ uint8_t test_5b_bad_parse_heap() {
return 1;
}

expect_uint("prompt len", 0, message.prompt_len);
expect_uint("token len", 0, message.token_len);
expect_uint("body len", 0, atserver_message_get_body_len(message));
expect_uint("len", 0, message.len);
expect_uint("prompt len", 0, "u", message.prompt_len);
expect_uint("token len", 0, "u", message.token_len);
expect_uint("body len", 0, "zu", atserver_message_get_body_len(message));
expect_uint("len", 0, "zu", message.len);

// ensure original heap buffer is intact
if (strncmp(heap_buffer, static_buffer, len - 1) != 0) {
Expand Down
4 changes: 2 additions & 2 deletions packages/atclient/tests/test_parse_at_prompt.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ int main() {
// returns 1 if EXP != ACT and logs the error
#define expect_size_t(TEST_TAG, EXP, ACT) \
if (EXP != ACT) { \
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "%s: wrong idx value (expected: %d, actual: %d)\n", TEST_TAG, EXP, \
ACT); \
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "%s: wrong idx value (expected: %d, actual: %zu)\n", TEST_TAG, \
EXP, ACT); \
return 1; \
}

Expand Down
3 changes: 2 additions & 1 deletion tests/functional_tests/tests/test_atclient_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ static int test_7_send_should_fail(atclient_connection *conn) {
ret = atclient_connection_send(conn, send_data, send_data_len, recv, recvsize, &recvlen);
if (ret == 0) {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR,
"Successfully sent \"%s\" when it should have resulted in a failure: %d\n", ret);
"Successfully sent \"%.*s\" when it should have resulted in a failure: %d\n", (int)send_data_len,
send_data, ret);
ret = 1;
goto exit;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/functional_tests/tests/test_atclient_publickey.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,18 +289,18 @@ static int test_6_get_with_metadata(atclient *atclient) {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_INFO, "atkey.metadata.ccd: %d\n", atkey.metadata.ccd);

if (atclient_atkey_metadata_is_ttl_initialized(&(atkey.metadata)) && atkey.metadata.ttl != ATKEY_TTL) {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed ttl comparison, got %d and expected %d\n",
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed ttl comparison, got %" PRIu64 " and expected %d\n",
atkey.metadata.ttl, ATKEY_TTL);
goto exit;
}
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_INFO, "atkey.metadata.ttl: %d\n", atkey.metadata.ttl);
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_INFO, "atkey.metadata.ttl: %" PRIu64 "\n", atkey.metadata.ttl);

if (atclient_atkey_metadata_is_ttr_initialized(&(atkey.metadata)) && atkey.metadata.ttr != ATKEY_TTR) {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed ttr comparison, got %d and expected %d\n",
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed ttr comparison, got %" PRIu64 " and expected %d\n",
atkey.metadata.ttr, ATKEY_TTR);
goto exit;
}
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_INFO, "atkey.metadata.ttr: %d\n", atkey.metadata.ttr);
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_INFO, "atkey.metadata.ttr: %" PRIu64 "\n", atkey.metadata.ttr);

if (atclient_atkey_metadata_is_is_encrypted_initialized(&(atkey.metadata)) &&
atkey.metadata.is_encrypted != ATKEY_ISENCRYPTED) {
Expand Down
6 changes: 3 additions & 3 deletions tests/functional_tests/tests/test_atclient_selfkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,12 @@ static int test_7_get_with_metadata(atclient *atclient) {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_INFO, "atkey.value: \"%s\" == \"%s\"\n", value, ATKEY_VALUE);

if (atkey.metadata.ttl != ATKEY_TTL) {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atkey.metadata.ttl: %d != %d\n", atkey.metadata.ttl, ATKEY_TTL);
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atkey.metadata.ttl: %" PRIu64 " != %d\n", atkey.metadata.ttl,
ATKEY_TTL);
ret = 1;
goto exit;
}
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_INFO, "atkey.metadata.ttl: %d\n", atkey.metadata.ttl);
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_INFO, "atkey.metadata.ttl: %" PRIu64 "\n", atkey.metadata.ttl);

if (atclient_atkey_metadata_is_is_encrypted_initialized(&atkey.metadata) &&
atkey.metadata.is_encrypted != ATKEY_ISENCRYPTED) {
Expand Down Expand Up @@ -403,7 +404,6 @@ static int tear_down(atclient *atclient) {
const size_t atkeystrsize = 128;
char atkeystr[atkeystrsize];
memset(atkeystr, 0, sizeof(char) * atkeystrsize);
size_t atkeystrlen = 0;

const size_t commandsize = 256;
char command[commandsize];
Expand Down
Loading

0 comments on commit 07c0318

Please sign in to comment.