aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Göthel <[email protected]>2024-05-19 17:17:56 +0200
committerSven Göthel <[email protected]>2024-05-19 17:17:56 +0200
commit71812af834c05ba4de6f7e0cfda68fd78eee9e0d (patch)
treeb2e4c5c19ed9e97f84f31a32a1c21c40fdf4cbdf
parent40dff9f3d26f74580f09d72715784aa46cb69e6d (diff)
Replace static arrays using non-standard (illegal) dynamic size with std::vector ...
-rw-r--r--include/jau/test/catch2_my_main.cpp20
-rw-r--r--include/jau/token_fsm.hpp11
-rw-r--r--test/test_bytestream01.cpp37
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 <vector>
+
#define CATCH_AMALGAMATED_CUSTOM_MAIN 1
#include <catch2/catch_amalgamated.hpp>
@@ -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<char*> argv_2;
+ argv_2.reserve(argc+extra_args_c);
for(int i=0; i<argc; i++) {
if( 0 == strcmp("--perf_analysis", argv[i]) ) {
catch_perf_analysis = true;
} else {
- argv_2[argc_2++] = argv[i];
+ argv_2.push_back(argv[i]);
}
}
for(int i=0; i<extra_args_c; i++) {
- argv_2[argc_2++] = extra_args[i];
+ argv_2.push_back(extra_args[i]);
}
- fprintf(stderr, "argc %d -> %d, auto_run %d, perf_analysis %d\n",
- argc, argc_2, catch_auto_run, catch_perf_analysis);
- for(int i=0; i<argc_2; i++) {
- printf("[%d] %s\n", i, argv_2[i]);
+ fprintf(stderr, "argc %d -> %zu, auto_run %d, perf_analysis %d\n",
+ argc, argv_2.size(), catch_auto_run, catch_perf_analysis);
+ for(size_t i=0; i<argv_2.size(); ++i) {
+ printf("[%zu] %s\n", i, argv_2[i]);
}
// writing to session.configData() here sets defaults
// this is the preferred way to set them
- int returnCode = session.applyCommandLine( argc_2, argv_2 );
+ int returnCode = session.applyCommandLine( argv_2.size(), argv_2.data() );
if( returnCode != 0 ) { // Indicates a command line error
return returnCode;
diff --git a/include/jau/token_fsm.hpp b/include/jau/token_fsm.hpp
index a2e5332..f54bf5e 100644
--- a/include/jau/token_fsm.hpp
+++ b/include/jau/token_fsm.hpp
@@ -283,13 +283,12 @@ namespace jau::lang {
}
private:
- typedef jau::darray<uint_t, jau::nsize_t> matrix_t;
+ typedef jau::darray<uint_t, jau::nsize_t> 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<uint_t> 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 <cassert>
#include <cinttypes>
+#include <cstdint>
#include <cstring>
+#include <vector>
#include <jau/test/catch2_ext.hpp>
@@ -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<uint8_t> 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<uint8_t> 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<uint8_t> 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<uint8_t> 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<uint8_t> 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;