core: Avoid trivial snprintfs.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 34m10s

This commit is contained in:
2025-06-10 21:17:55 -04:00
parent 3a2a829940
commit b135a210cc
13 changed files with 96 additions and 74 deletions

View File

@ -789,10 +789,10 @@ void tf_ssb_db_store_message(
.callback = callback,
.user_data = user_data,
};
snprintf(store->id, sizeof(store->id), "%s", id);
snprintf(store->previous, sizeof(store->previous), "%s", previous ? previous : "");
snprintf(store->author, sizeof(store->author), "%s", author);
snprintf(store->signature, sizeof(store->signature), "%s", signature);
tf_string_set(store->id, sizeof(store->id), id);
tf_string_set(store->previous, sizeof(store->previous), previous ? previous : "");
tf_string_set(store->author, sizeof(store->author), author);
tf_string_set(store->signature, sizeof(store->signature), signature);
JS_FreeCString(context, author);
JS_FreeCString(context, previous);
@ -949,7 +949,7 @@ void tf_ssb_db_blob_get_async(tf_ssb_t* ssb, const char* id, tf_ssb_db_blob_get_
.callback = callback,
.user_data = user_data,
};
snprintf(async->id, sizeof(async->id), "%s", id);
tf_string_set(async->id, sizeof(async->id), id);
tf_ssb_run_work(ssb, _tf_ssb_db_blob_get_async_work, _tf_ssb_db_blob_get_async_after_work, async);
}
@ -1046,7 +1046,7 @@ bool tf_ssb_db_blob_store(tf_ssb_t* ssb, const uint8_t* blob, size_t size, char*
if (result && out_id)
{
snprintf(out_id, out_id_size, "%s", id);
tf_string_set(out_id, out_id_size, id);
}
if (out_new)
{
@ -1068,7 +1068,7 @@ bool tf_ssb_db_get_message_by_author_and_sequence(tf_ssb_t* ssb, const char* aut
{
if (out_message_id)
{
snprintf(out_message_id, out_message_id_size, "%s", (const char*)sqlite3_column_text(statement, 0));
tf_string_set(out_message_id, out_message_id_size, (const char*)sqlite3_column_text(statement, 0));
}
if (out_previous)
{
@ -1081,7 +1081,7 @@ bool tf_ssb_db_get_message_by_author_and_sequence(tf_ssb_t* ssb, const char* aut
}
else
{
snprintf(out_previous, out_previous_size, "%s", (const char*)sqlite3_column_text(statement, 1));
tf_string_set(out_previous, out_previous_size, (const char*)sqlite3_column_text(statement, 1));
}
}
if (out_timestamp)
@ -1094,11 +1094,11 @@ bool tf_ssb_db_get_message_by_author_and_sequence(tf_ssb_t* ssb, const char* aut
}
if (out_hash)
{
snprintf(out_hash, out_hash_size, "%s", (const char*)sqlite3_column_text(statement, 4));
tf_string_set(out_hash, out_hash_size, (const char*)sqlite3_column_text(statement, 4));
}
if (out_signature)
{
snprintf(out_signature, out_signature_size, "%s", (const char*)sqlite3_column_text(statement, 5));
tf_string_set(out_signature, out_signature_size, (const char*)sqlite3_column_text(statement, 5));
}
if (out_flags)
{
@ -1651,7 +1651,7 @@ static following_t* _make_following_node(const char* id, following_t*** followin
(*following_count)++;
memset(entry, 0, sizeof(*entry));
entry->depth = INT_MAX;
snprintf(entry->id, sizeof(entry->id), "%s", id);
tf_string_set(entry->id, sizeof(entry->id), id);
}
return entry;
}
@ -1785,7 +1785,7 @@ tf_ssb_following_t* tf_ssb_db_following_deep(tf_ssb_t* ssb, const char** ids, in
{
if (following[i]->ref_count > 0 || include_blocks)
{
snprintf(result[write_index].id, sizeof(result[write_index].id), "%s", following[i]->id);
tf_string_set(result[write_index].id, sizeof(result[write_index].id), following[i]->id);
result[write_index].following_count = following[i]->following_count;
result[write_index].blocking_count = following[i]->blocking_count;
result[write_index].followed_by_count = following[i]->ref_count;
@ -1840,7 +1840,7 @@ const char** tf_ssb_db_following_deep_ids(tf_ssb_t* ssb, const char** ids, int c
if (following[i]->ref_count > 0)
{
result[write_index] = result_ids + k_id_base64_len * write_index;
snprintf(result[write_index], k_id_base64_len, "%s", following[i]->id);
tf_string_set(result[write_index], k_id_base64_len, following[i]->id);
write_index++;
}
}
@ -1939,8 +1939,8 @@ tf_ssb_db_stored_connection_t* tf_ssb_db_get_stored_connections(tf_ssb_t* ssb, i
.last_attempt = sqlite3_column_int64(statement, 3),
.last_success = sqlite3_column_int64(statement, 4),
};
snprintf(result[count].address, sizeof(result[count].address), "%s", (const char*)sqlite3_column_text(statement, 0));
snprintf(result[count].pubkey, sizeof(result[count].pubkey), "%s", (const char*)sqlite3_column_text(statement, 2));
tf_string_set(result[count].address, sizeof(result[count].address), (const char*)sqlite3_column_text(statement, 0));
tf_string_set(result[count].pubkey, sizeof(result[count].pubkey), (const char*)sqlite3_column_text(statement, 2));
count++;
}
sqlite3_finalize(statement);
@ -1978,7 +1978,7 @@ bool tf_ssb_db_get_account_password_hash(tf_ssb_t* ssb, const char* name, char*
{
if (sqlite3_step(statement) == SQLITE_ROW)
{
snprintf(out_password, password_size, "%s", (const char*)sqlite3_column_text(statement, 0));
tf_string_set(out_password, password_size, (const char*)sqlite3_column_text(statement, 0));
result = true;
}
}
@ -2176,7 +2176,7 @@ bool tf_ssb_db_identity_get_active(sqlite3* db, const char* user, const char* pa
if (sqlite3_bind_text(statement, 1, user, -1, NULL) == SQLITE_OK && sqlite3_bind_text(statement, 2, package_owner, -1, NULL) == SQLITE_OK &&
sqlite3_bind_text(statement, 3, package_name, -1, NULL) == SQLITE_OK && sqlite3_step(statement) == SQLITE_ROW)
{
snprintf(out_identity, out_identity_size, "%s", (const char*)sqlite3_column_text(statement, 0));
tf_string_set(out_identity, out_identity_size, (const char*)sqlite3_column_text(statement, 0));
found = true;
}
sqlite3_finalize(statement);
@ -2446,7 +2446,7 @@ bool tf_ssb_db_get_global_setting_string(sqlite3* db, const char* name, char* ou
{
if (sqlite3_step(statement) == SQLITE_ROW && sqlite3_column_type(statement, 0) != SQLITE_NULL)
{
snprintf(out_value, size, "%s", sqlite3_column_text(statement, 0));
tf_string_set(out_value, size, (const char*)sqlite3_column_text(statement, 0));
result = true;
}
}
@ -2458,7 +2458,7 @@ bool tf_ssb_db_get_global_setting_string(sqlite3* db, const char* name, char* ou
}
if (!result)
{
snprintf(out_value, size, "%s", tf_util_get_default_global_setting_string(name));
tf_string_set(out_value, size, tf_util_get_default_global_setting_string(name));
}
return result;
}
@ -2740,7 +2740,7 @@ tf_ssb_identity_info_t* tf_ssb_db_get_identity_info(tf_ssb_t* ssb, const char* u
tf_ssb_db_identity_get_active(db, user, package_owner, package_name, info->active_identity, sizeof(info->active_identity));
if (!*info->active_identity && info->count)
{
snprintf(info->active_identity, sizeof(info->active_identity), "%s", info->identity[0]);
tf_string_set(info->active_identity, sizeof(info->active_identity), info->identity[0]);
}
tf_ssb_release_db_reader(ssb, db);