@@ -218,34 +218,33 @@ void QlManager::select_from(std::unique_ptr<AbstractExecutor> executorTreeRoot,
218218 // Print records
219219 size_t num_rec = 0 ;
220220 // 执行query_plan
221- char buffer[BUFFER_LENGTH ];
222- int offset = 0 ;
223- int size;
221+ constexpr int BUFFER_SIZE = BUFFER_LENGTH ;
222+ char buffer[BUFFER_SIZE ];
224223 for (executorTreeRoot->beginTuple (); !executorTreeRoot->is_end (); executorTreeRoot->nextTuple ()) {
225224 auto Tuple = executorTreeRoot->Next ();
226225 const auto &cols = executorTreeRoot->cols ();
227226 std::vector<std::string_view> columns;
228227 columns.reserve (cols.size ());
228+ size_t offset = 0 ;
229+ size_t size;
229230 for (auto &col : cols) {
230231 char *rec_buf = Tuple->data + col.offset ;
231232 switch (col.type ) {
232233 case ColType::TYPE_INT :
233- size = sprintf (buffer + offset, " %d" , *(int *)rec_buf);
234+ size = snprintf (buffer + offset, BUFFER_SIZE - offset, " %d" , *(int *)rec_buf);
234235 columns.emplace_back (buffer + offset, size);
235236 offset += size;
236237 break ;
237238 case ColType::TYPE_FLOAT :
238- size = sprintf (buffer + offset, " %.6f" , *(float *)rec_buf); // 更简洁的浮点表示
239+ size = snprintf (buffer + offset, BUFFER_SIZE - offset, " %.6f" , *(float *)rec_buf); // 更简洁的浮点表示
239240 columns.emplace_back (buffer + offset, size);
240241 offset += size;
241242 break ;
242243 case ColType::TYPE_STRING :
243- size_t actual_len = strnlen (rec_buf, col.len );
244- columns.emplace_back (rec_buf, actual_len);
244+ columns.emplace_back (rec_buf, strnlen (rec_buf, col.len ));
245245 break ;
246246 }
247247 }
248- NXT :;
249248 // print record into buffer
250249 rec_printer.print_record (columns, context);
251250 // print record into file
0 commit comments