Skip to content

Commit 3287e47

Browse files
committed
sprintf -> snprintf replacement inside ydb code
1 parent 90294b5 commit 3287e47

File tree

6 files changed

+10
-10
lines changed

6 files changed

+10
-10
lines changed

ydb/core/base/logoblob.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ TString TLogoBlobID::ToString() const {
1818

1919
void TLogoBlobID::Out(IOutputStream &o) const {
2020
char buf[240];
21-
sprintf(buf,
21+
snprintf(buf, sizeof(buf),
2222
"[%" PRIu64 ":%" PRIu32 ":%" PRIu32 ":%" PRIu32 ":%" PRIu32 ":%" PRIu32 ":%" PRIu32 "]",
2323
TabletID(),
2424
Generation(),

ydb/core/base/traceid.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ TString TTraceID::ToString() const {
2828

2929
void TTraceID::Out(IOutputStream &o) const {
3030
char buf[240];
31-
sprintf(buf, "[ID:%" PRIu64 ", Created: %s]", RandomID, TInstant::MicroSeconds(CreationTime).ToRfc822StringLocal().data());
31+
snprintf(buf, sizeof(buf), "[ID:%" PRIu64 ", Created: %s]", RandomID, TInstant::MicroSeconds(CreationTime).ToRfc822StringLocal().data());
3232
o << buf;
3333
}
3434

ydb/library/workload/stock_workload.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ TQueryInfo TStockWorkloadGenerator::FillStockData() const {
102102
INSERT INTO `stock`(product, quantity) SELECT product, quantity from AS_TABLE( $stocks );
103103
)";
104104

105-
char productName[8] = "";
106105
NYdb::TValueBuilder rows;
107106
rows.BeginList();
108107
for (size_t i = 0; i < Params.ProductCount; ++i) {
109-
std::sprintf(productName, "p%.6zu", i);
108+
char productName[8] = "";
109+
std::snprintf(productName, sizeof(productName), "p%.6zu", i);
110110
rows.AddListItem()
111111
.BeginStruct()
112112
.AddMember("product").Utf8(productName)
@@ -238,10 +238,10 @@ unsigned int TStockWorkloadGenerator::GetProductCountInOrder() {
238238
}
239239

240240
TStockWorkloadGenerator::TProductsQuantity TStockWorkloadGenerator::GenerateOrder(unsigned int productCountInOrder, int quantity) {
241-
char productName[8] = "";
242241
TProductsQuantity products;
243242
for (unsigned i = 0; i < productCountInOrder; ++i) {
244-
std::sprintf(productName, "p%.6i", ProductIdGenerator(Gen));
243+
char productName[8] = "";
244+
std::snprintf(productName, sizeof(productName), "p%.6i", ProductIdGenerator(Gen));
245245
products.emplace(productName, quantity);
246246
}
247247
return products;
@@ -277,7 +277,7 @@ TQueryInfoList TStockWorkloadGenerator::SubmitSameOrder() {
277277
char productName[8] = "";
278278
TProductsQuantity products;
279279
for (unsigned i = 0; i < Params.ProductCount; ++i) {
280-
std::sprintf(productName, "p%.6i", i);
280+
std::snprintf(productName, sizeof(productName), "p%.6i", i);
281281
products.emplace(productName, 1);
282282
}
283283
res.push_back(InsertOrder(orderID, customer, products));

ydb/library/yql/ast/yql_expr.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2724,7 +2724,7 @@ TAstParseResult ConvertToAst(const TExprNode& root, TExprContext& exprContext, c
27242724
YQL_ENSURE(frame.Bindings.emplace(node.second, buffer).second);
27252725
} else {
27262726
char buffer[1 + 10 + 1];
2727-
sprintf(buffer, "$%" PRIu32, ++uniqueNum);
2727+
snprintf(buffer, sizeof(buffer), "$%" PRIu32, ++uniqueNum);
27282728
YQL_ENSURE(frame.Bindings.emplace(node.second, buffer).second);
27292729
}
27302730
frame.TopoSortedNodes.emplace_back(node.second);

ydb/public/lib/ydb_cli/commands/click_bench.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ int TClickBenchCommandClean::Run(TConfig& config) {
470470
static const char DropDdlTmpl[] = "DROP TABLE `%s`;";
471471
char dropDdl[sizeof(DropDdlTmpl) + 8192*3]; // 32*256 for DbPath
472472
TString fullPath = FullTablePath(config.Database, Table);
473-
int res = std::sprintf(dropDdl, DropDdlTmpl, fullPath.c_str());
473+
int res = std::snprintf(dropDdl, sizeof(dropDdl), DropDdlTmpl, fullPath.c_str());
474474
if (res < 0) {
475475
Cerr << "Failed to generate DROP DDL query for `" << fullPath << "` table." << Endl;
476476
return -1;

ydb/public/lib/ydb_cli/commands/tpch.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ int TTpchCommandClean::Run(TConfig& config) {
291291
char dropDdl[sizeof(DropDdlTmpl) + 8192*3]; // 32*256 for DbPath
292292
for (auto& table : Tables) {
293293
TString fullPath = FullTablePath(config.Database, table);
294-
int res = std::sprintf(dropDdl, DropDdlTmpl, fullPath.c_str());
294+
int res = std::snprintf(dropDdl, sizeof(dropDdl), DropDdlTmpl, fullPath.c_str());
295295
if (res < 0) {
296296
Cerr << "Failed to generate DROP DDL query for `" << fullPath << "` table." << Endl;
297297
return -1;

0 commit comments

Comments
 (0)