From 71812af834c05ba4de6f7e0cfda68fd78eee9e0d Mon Sep 17 00:00:00 2001 From: Sven Göthel Date: Sun, 19 May 2024 17:17:56 +0200 Subject: Replace static arrays using non-standard (illegal) dynamic size with std::vector ... --- include/jau/test/catch2_my_main.cpp | 20 +++++++++++--------- include/jau/token_fsm.hpp | 11 +++++------ test/test_bytestream01.cpp | 37 ++++++++++++++++++++++--------------- 3 files changed, 38 insertions(+), 30 deletions(-) diff --git a/include/jau/test/catch2_my_main.cpp b/include/jau/test/catch2_my_main.cpp index 1a0b625..ea343b3 100644 --- a/include/jau/test/catch2_my_main.cpp +++ b/include/jau/test/catch2_my_main.cpp @@ -33,6 +33,8 @@ #ifndef CATCH2_MY_MAIN_H #define CATCH2_MY_MAIN_H +#include + #define CATCH_AMALGAMATED_CUSTOM_MAIN 1 #include @@ -60,29 +62,29 @@ int main( int argc, char* argv[] ) catch_auto_run = ( 1 >= argc ); - int argc_2=0; - char* argv_2[argc+extra_args_c]; + std::vector argv_2; + argv_2.reserve(argc+extra_args_c); for(int i=0; i %d, auto_run %d, perf_analysis %d\n", - argc, argc_2, catch_auto_run, catch_perf_analysis); - for(int i=0; i %zu, auto_run %d, perf_analysis %d\n", + argc, argv_2.size(), catch_auto_run, catch_perf_analysis); + for(size_t i=0; i matrix_t; + typedef jau::darray darray_t; void grow(const uint_t required_sz) { + m_matrix.reserve( required_sz + 100 ); while( m_matrix.size() < required_sz ) { - uint_t line[m_row_len]; - zero_bytes_sec(line, sizeof(line)); - m_matrix.push_back(&line[0], &line[m_row_len]); + m_matrix.resize(m_matrix.size() + m_row_len, 0); } } @@ -298,9 +297,9 @@ namespace jau::lang { uint_t m_end; std::string m_separators; - matrix_t m_matrix; + darray_t m_matrix; uint_t m_next_state; - std::vector m_token_names; + darray_t m_token_names; public: diff --git a/test/test_bytestream01.cpp b/test/test_bytestream01.cpp index a2792b4..90b3746 100644 --- a/test/test_bytestream01.cpp +++ b/test/test_bytestream01.cpp @@ -24,7 +24,9 @@ #include #include +#include #include +#include #include @@ -444,12 +446,13 @@ class TestByteStream01 { static void feed_source_00(jau::io::ByteInStream_Feed * data_feed, const size_t feed_size=1024) { uint64_t xfer_total = 0; jau::io::ByteInStream_File data_stream(data_feed->id()); - uint8_t buffer[feed_size]; + std::vector buffer; + buffer.resize(feed_size); while( data_stream.good() ) { - size_t count = data_stream.read(buffer, sizeof(buffer)); + size_t count = data_stream.read(buffer.data(), buffer.size()); if( 0 < count ) { xfer_total += count; - if( data_feed->write(buffer, count) ) { + if( data_feed->write(buffer.data(), count) ) { jau::sleep_for( 16_ms ); } else { break; @@ -467,12 +470,13 @@ class TestByteStream01 { jau::io::ByteInStream_File data_stream(data_feed->id()); const uint64_t file_size = data_stream.content_size(); data_feed->set_content_size( file_size ); - uint8_t buffer[feed_size]; + std::vector buffer; + buffer.resize(feed_size); while( data_stream.good() && xfer_total < file_size ) { - size_t count = data_stream.read(buffer, sizeof(buffer)); + size_t count = data_stream.read(buffer.data(), buffer.size()); if( 0 < count ) { xfer_total += count; - if( data_feed->write(buffer, count) ) { + if( data_feed->write(buffer.data(), count) ) { jau::sleep_for( 16_ms ); } else { break; @@ -489,12 +493,13 @@ class TestByteStream01 { jau::io::ByteInStream_File data_stream(data_feed->id()); const uint64_t file_size = data_stream.content_size(); data_feed->set_content_size( data_stream.content_size() ); - uint8_t buffer[feed_size]; + std::vector buffer; + buffer.resize(feed_size); while( data_stream.good() && xfer_total < file_size ) { - size_t count = data_stream.read(buffer, sizeof(buffer)); + size_t count = data_stream.read(buffer.data(), buffer.size()); if( 0 < count ) { xfer_total += count; - if( !data_feed->write(buffer, count) ) { + if( !data_feed->write(buffer.data(), count) ) { break; } } @@ -506,12 +511,13 @@ class TestByteStream01 { static void feed_source_20(jau::io::ByteInStream_Feed * data_feed, const size_t feed_size=1024) { uint64_t xfer_total = 0; jau::io::ByteInStream_File data_stream(data_feed->id()); - uint8_t buffer[feed_size]; + std::vector buffer; + buffer.resize(feed_size); while( data_stream.good() ) { - size_t count = data_stream.read(buffer, sizeof(buffer)); + size_t count = data_stream.read(buffer.data(), buffer.size()); if( 0 < count ) { xfer_total += count; - if( data_feed->write(buffer, count) ) { + if( data_feed->write(buffer.data(), count) ) { if( xfer_total >= 1024 ) { data_feed->set_eof( jau::io::async_io_result_t::FAILED ); // calls data_feed->interruptReader(); return; @@ -531,12 +537,13 @@ class TestByteStream01 { jau::io::ByteInStream_File data_stream(data_feed->id()); const uint64_t file_size = data_stream.content_size(); data_feed->set_content_size( data_stream.content_size() ); - uint8_t buffer[feed_size]; + std::vector buffer; + buffer.resize(feed_size); while( data_stream.good() ) { - size_t count = data_stream.read(buffer, sizeof(buffer)); + size_t count = data_stream.read(buffer.data(), buffer.size()); if( 0 < count ) { xfer_total += count; - if( data_feed->write(buffer, count) ) { + if( data_feed->write(buffer.data(), count) ) { if( xfer_total >= file_size/4 ) { data_feed->set_eof( jau::io::async_io_result_t::FAILED ); // calls data_feed->interruptReader(); return; -- cgit v1.2.3