Skip to content

Commit 8e67d24

Browse files
committed
Replaced all %lld (except one)
1 parent b901b36 commit 8e67d24

File tree

7 files changed

+28
-24
lines changed

7 files changed

+28
-24
lines changed

src/cloudsync.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,7 +1739,7 @@ int cloudsync_finalize_alter (cloudsync_context *data, cloudsync_table_context *
17391739

17401740
// update key to be later used in cloudsync_dbversion_rebuild
17411741
char buf[256];
1742-
snprintf(buf, sizeof(buf), "%lld", data->db_version);
1742+
snprintf(buf, sizeof(buf), "%" PRId64, data->db_version);
17431743
dbutils_settings_set_key_value(db, NULL, "pre_alter_dbversion", buf);
17441744

17451745
finalize:
@@ -2310,7 +2310,7 @@ int cloudsync_payload_apply (cloudsync_context *data, const char *payload, int b
23102310
if (rc != DBRES_DONE) {
23112311
// don't "break;", the error can be due to a RLS policy.
23122312
// in case of error we try to apply the following changes
2313-
// printf("cloudsync_payload_apply error on db_version %lld/%lld: (%d) %s\n", decoded_context.db_version, decoded_context.seq, rc, database_errmsg(db));
2313+
// printf("cloudsync_payload_apply error on db_version %PRId64/%PRId64: (%d) %s\n", decoded_context.db_version, decoded_context.seq, rc, database_errmsg(db));
23142314
}
23152315
}
23162316

@@ -2341,11 +2341,11 @@ int cloudsync_payload_apply (cloudsync_context *data, const char *payload, int b
23412341
if (rc == DBRES_OK) {
23422342
char buf[256];
23432343
if (decoded_context.db_version >= dbversion) {
2344-
snprintf(buf, sizeof(buf), "%lld", decoded_context.db_version);
2344+
snprintf(buf, sizeof(buf), "%" PRId64, decoded_context.db_version);
23452345
dbutils_settings_set_key_value(db, NULL, CLOUDSYNC_KEY_CHECK_DBVERSION, buf);
23462346

23472347
if (decoded_context.seq != seq) {
2348-
snprintf(buf, sizeof(buf), "%lld", decoded_context.seq);
2348+
snprintf(buf, sizeof(buf), "%" PRId64, decoded_context.seq);
23492349
dbutils_settings_set_key_value(db, NULL, CLOUDSYNC_KEY_CHECK_SEQ, buf);
23502350
}
23512351
}
@@ -2428,11 +2428,11 @@ int cloudsync_payload_save (cloudsync_context *data, const char *payload_path, i
24282428
char buf[256];
24292429
db_t *db = data->db;
24302430
if (new_db_version != db_version) {
2431-
snprintf(buf, sizeof(buf), "%lld", new_db_version);
2431+
snprintf(buf, sizeof(buf), "%" PRId64, new_db_version);
24322432
dbutils_settings_set_key_value(db, NULL, CLOUDSYNC_KEY_SEND_DBVERSION, buf);
24332433
}
24342434
if (new_seq != seq) {
2435-
snprintf(buf, sizeof(buf), "%lld", new_seq);
2435+
snprintf(buf, sizeof(buf), "%" PRId64, new_seq);
24362436
dbutils_settings_set_key_value(db, NULL, CLOUDSYNC_KEY_SEND_SEQ, buf);
24372437
}
24382438

src/database_sqlite.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "utils.h"
1212
#include "sql.h"
1313

14+
#include <inttypes.h>
1415
#include <string.h>
1516
#include <stdlib.h>
1617

@@ -547,7 +548,7 @@ bool database_check_schema_hash (db_t *db, uint64_t hash) {
547548
// the idea is to allow changes on stale peers and to be able to apply these changes on peers with newer schema,
548549
// but it requires alter table operation on augmented tables only add new columns and never drop columns for backward compatibility
549550
char sql[1024];
550-
snprintf(sql, sizeof(sql), "SELECT 1 FROM cloudsync_schema_versions WHERE hash = (%lld)", hash);
551+
snprintf(sql, sizeof(sql), "SELECT 1 FROM cloudsync_schema_versions WHERE hash = (%" PRId64 ")", hash);
551552

552553
int64_t value = 0;
553554
database_select_int(db, sql, &value);
@@ -570,9 +571,9 @@ int database_update_schema_hash (db_t *db, uint64_t *hash) {
570571

571572
char sql[1024];
572573
snprintf(sql, sizeof(sql), "INSERT INTO cloudsync_schema_versions (hash, seq) "
573-
"VALUES (%lld, COALESCE((SELECT MAX(seq) FROM cloudsync_schema_versions), 0) + 1) "
574+
"VALUES (%" PRId64 ", COALESCE((SELECT MAX(seq) FROM cloudsync_schema_versions), 0) + 1) "
574575
"ON CONFLICT(hash) DO UPDATE SET "
575-
"seq = (SELECT COALESCE(MAX(seq), 0) + 1 FROM cloudsync_schema_versions);", (long long)h);
576+
"seq = (SELECT COALESCE(MAX(seq), 0) + 1 FROM cloudsync_schema_versions);", h);
576577
rc = database_exec(db, sql);
577578
if (rc == SQLITE_OK && hash) *hash = h;
578579
return rc;

src/dbutils.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
//
77

88
#include <stdlib.h>
9+
#include <inttypes.h>
10+
911
#include "sql.h"
1012
#include "utils.h"
1113
#include "dbutils.h"
@@ -71,7 +73,7 @@ int dbutils_value_compare (dbvalue_t *lvalue, dbvalue_t *rvalue) {
7173
void dbutils_debug_value (dbvalue_t *value) {
7274
switch (database_value_type(value)) {
7375
case DBTYPE_INTEGER:
74-
printf("\t\tINTEGER: %lld\n", database_value_int(value));
76+
printf("\t\tINTEGER: %" PRId64 "\n", database_value_int(value));
7577
break;
7678
case DBTYPE_FLOAT:
7779
printf("\t\tFLOAT: %f\n", database_value_double(value));

src/network.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -682,8 +682,7 @@ void cloudsync_network_set_apikey (sqlite3_context *context, int argc, sqlite3_v
682682
void cloudsync_network_has_unsent_changes (sqlite3_context *context, int argc, sqlite3_value **argv) {
683683
sqlite3 *db = sqlite3_context_db_handle(context);
684684

685-
// TODO: why hex(site_id) here if only one int column is returned?
686-
char *sql = "SELECT max(db_version), hex(site_id) FROM cloudsync_changes WHERE site_id == (SELECT site_id FROM cloudsync_site_id WHERE rowid=0)";
685+
char *sql = "SELECT max(db_version) FROM cloudsync_changes WHERE site_id == (SELECT site_id FROM cloudsync_site_id WHERE rowid=0)";
687686
int64_t last_local_change = 0;
688687
int rc = database_select_int(db, sql, &last_local_change);
689688
if (rc != DBRES_OK) {
@@ -759,11 +758,11 @@ int cloudsync_network_send_changes_internal (sqlite3_context *context, int argc,
759758
char buf[256];
760759
sqlite3 *db = sqlite3_context_db_handle(context);
761760
if (new_db_version != db_version) {
762-
snprintf(buf, sizeof(buf), "%lld", new_db_version);
761+
snprintf(buf, sizeof(buf), "%" PRId64, new_db_version);
763762
dbutils_settings_set_key_value(db, data, CLOUDSYNC_KEY_SEND_DBVERSION, buf);
764763
}
765764
if (new_seq != seq) {
766-
snprintf(buf, sizeof(buf), "%lld", new_seq);
765+
snprintf(buf, sizeof(buf), "%" PRId64, new_seq);
767766
dbutils_settings_set_key_value(db, data, CLOUDSYNC_KEY_SEND_SEQ, buf);
768767
}
769768

@@ -793,7 +792,7 @@ int cloudsync_network_check_internal(sqlite3_context *context, int *pnrows) {
793792
// http://uuid.g5.sqlite.cloud/v1/cloudsync/{dbname}/{site_id}/{db_version}/{seq}/check
794793
// the data->check_endpoint stops after {site_id}, just need to append /{db_version}/{seq}/check
795794
char endpoint[2024];
796-
snprintf(endpoint, sizeof(endpoint), "%s/%lld/%d/%s", data->check_endpoint, (long long)db_version, seq, CLOUDSYNC_ENDPOINT_CHECK);
795+
snprintf(endpoint, sizeof(endpoint), "%s/%" PRId64 "/%d/%s", data->check_endpoint, db_version, seq, CLOUDSYNC_ENDPOINT_CHECK);
797796

798797
NETWORK_RESULT result = network_receive_buffer(data, endpoint, data->authentication, true, true, NULL, CLOUDSYNC_HEADER_SQLITECLOUD);
799798
int rc = SQLITE_OK;

src/pk.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "pk.h"
99
#include "utils.h"
10+
#include <inttypes.h>
1011

1112
/*
1213
@@ -110,7 +111,7 @@ int pk_decode_bind_callback (void *xdata, int index, int type, int64_t ival, dou
110111
int pk_decode_print_callback (void *xdata, int index, int type, int64_t ival, double dval, char *pval) {
111112
switch (type) {
112113
case DBTYPE_INTEGER:
113-
printf("%d\tINTEGER:\t%lld\n", index, (long long)ival);
114+
printf("%d\tINTEGER:\t%" PRId64 "\n", index, ival);
114115
break;
115116

116117
case DBTYPE_FLOAT:
@@ -126,7 +127,7 @@ int pk_decode_print_callback (void *xdata, int index, int type, int64_t ival, do
126127
break;
127128

128129
case DBTYPE_BLOB:
129-
printf("%d\tBLOB:\t%lld bytes\n", index, (long long)ival);
130+
printf("%d\tBLOB:\t%" PRId64 " bytes\n", index, ival);
130131
break;
131132
}
132133

src/utils.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ void memdebug_finalize (void) {
586586
void *memdebug_alloc (uint64_t size) {
587587
void *ptr = dbmem_alloc(size);
588588
if (!ptr) {
589-
BUILD_ERROR("Unable to allocated a block of %lld bytes", size);
589+
BUILD_ERROR("Unable to allocated a block of %" PRIu64" bytes", size);
590590
BUILD_STACK(n, stack);
591591
memdebug_report(current_error, stack, n, NULL);
592592
return NULL;
@@ -617,7 +617,7 @@ void *memdebug_realloc (void *ptr, uint64_t new_size) {
617617
void *back_ptr = ptr;
618618
void *new_ptr = dbmem_realloc(ptr, new_size);
619619
if (!new_ptr) {
620-
BUILD_ERROR("Unable to reallocate a block of %lld bytes.", new_size);
620+
BUILD_ERROR("Unable to reallocate a block of %" PRIu64 " bytes.", new_size);
621621
BUILD_STACK(n, stack);
622622
memdebug_report(current_error, stack, n, slot);
623623
return NULL;

test/unit.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <string.h>
1111
#include <stdlib.h>
1212
#include <stdbool.h>
13+
#include <inttypes.h>
1314
#include <fcntl.h>
1415
#include "sqlite3.h"
1516

@@ -1108,12 +1109,12 @@ bool do_test_functions (sqlite3 *db, bool print_results) {
11081109
int64_t db_version = 0;
11091110
rc = database_select_int(db, "SELECT cloudsync_db_version();", &db_version);
11101111
if (rc != DBRES_OK) goto abort_test_functions;
1111-
if (print_results) printf("DB Version: %lld\n", db_version);
1112+
if (print_results) printf("DB Version: %" PRId64 "\n", db_version);
11121113

11131114
int64_t db_version_next = 0;
11141115
rc = database_select_int(db, "SELECT cloudsync_db_version_next();", &db_version);
11151116
if (rc != DBRES_OK) goto abort_test_functions;
1116-
if (print_results) printf("DB Version Next: %lld\n", db_version_next);
1117+
if (print_results) printf("DB Version Next: %" PRId64 "\n", db_version_next);
11171118

11181119
rc = sqlite3_exec(db, "CREATE TABLE tbl1 (col1 TEXT PRIMARY KEY NOT NULL, col2);", NULL, NULL, NULL);
11191120
if (rc != SQLITE_OK) goto abort_test_functions;
@@ -1472,7 +1473,7 @@ bool do_test_pk_single_value (sqlite3 *db, int type, int64_t ivalue, double dval
14721473

14731474
pklist[0].type = type;
14741475
if (type == SQLITE_INTEGER) {
1475-
snprintf(sql, sizeof(sql), "SELECT cloudsync_pk_encode(%lld);", ivalue);
1476+
snprintf(sql, sizeof(sql), "SELECT cloudsync_pk_encode(%" PRId64 ");", ivalue);
14761477
pklist[0].ivalue = ivalue;
14771478
} else if (type == SQLITE_FLOAT) {
14781479
snprintf(sql, sizeof(sql), "SELECT cloudsync_pk_encode(%f);", dvalue);
@@ -6289,10 +6290,10 @@ int main (int argc, const char * argv[]) {
62896290

62906291
cloudsync_memory_finalize();
62916292

6292-
sqlite3_int64 memory_used = sqlite3_memory_used();
6293+
int64_t memory_used = (int64_t)sqlite3_memory_used();
62936294
result += test_report("Memory Leaks Check:", memory_used == 0);
62946295
if (memory_used > 0) {
6295-
printf("\tleaked: %lld B\n", memory_used);
6296+
printf("\tleaked: %" PRId64 " B\n", memory_used);
62966297
result++;
62976298
}
62986299

0 commit comments

Comments
 (0)