kou commented on a change in pull request #11399:
URL: https://github.com/apache/arrow/pull/11399#discussion_r730575198
##########
File path: cpp/examples/parquet/parquet_stream_api/stream_reader_writer.cc
##########
@@ -136,12 +137,14 @@ struct TestData {
return "Str #" + std::to_string(i);
}
static arrow::util::string_view GetStringView(const int i) {
- string_ = "StringView #" + std::to_string(i);
+ int length = snprintf(string_, str_buff_size, "StringView #%d", i);
+ snprintf(string_, length + 1, "StringView #%d", i);
return arrow::util::string_view(string_);
Review comment:
I tried this:
```diff
diff --git a/cpp/examples/parquet/parquet_stream_api/stream_reader_writer.cc
b/cpp/examples/parquet/parquet_stream_api/stream_reader_writer.cc
index 474c9c286..464f210c7 100644
--- a/cpp/examples/parquet/parquet_stream_api/stream_reader_writer.cc
+++ b/cpp/examples/parquet/parquet_stream_api/stream_reader_writer.cc
@@ -137,14 +137,14 @@ struct TestData {
return "Str #" + std::to_string(i);
}
static arrow::util::string_view GetStringView(const int i) {
- int length = snprintf(string_, str_buff_size, "StringView #%d", i);
- snprintf(string_, length + 1, "StringView #%d", i);
- return arrow::util::string_view(string_);
+ static std::string string;
+ string = "StringView #" + std::to_string(i);
+ return arrow::util::string_view(string);
}
static const char* GetCharPtr(const int i) {
- int length = snprintf(string_, str_buff_size, "CharPtr #%d", i);
- snprintf(string_, length + 1, "CharPtr #%d", i);
- return string_;
+ static std::string string;
+ string = "CharPtr #" + std::to_string(i);
+ return string.c_str();
}
static char GetChar(const int i) { return i & 1 ? 'M' : 'F'; }
static int8_t GetInt8(const int i) { return static_cast<int8_t>((i % 256)
- 128); }
@@ -166,7 +166,6 @@ struct TestData {
private:
static std::time_t ts_offset_;
- static char string_[str_buff_size];
};
char TestData::char4_array[] = "XYZ";
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]