diff --git a/alib2cli/src/builtin/Dot.cpp b/alib2cli/src/builtin/Dot.cpp index 24c2b8c59cdc498467f7c0cbec57d3b71b5c95e1..20baf1d861a4140f6b93d0ca32696162284f739c 100644 --- a/alib2cli/src/builtin/Dot.cpp +++ b/alib2cli/src/builtin/Dot.cpp @@ -16,8 +16,8 @@ namespace cli::builtin { std::vector < std::string> Dot::allowedOutputTypes { "dot", "xdot", "ps", "pdf", "svg", "svgz", "fig", "png", "gif", "jpg", "jpeg", "json", "imap", "cmapx" }; void Dot::run ( const std::string & data, const std::string & outputType, const std::optional < std::string > & outputFile, bool runInBackground ) { - int fd [ 2 ]; - if ( pipe ( fd ) != 0 ) + std::array < int, 2 > fd; + if ( pipe ( fd.data ( ) ) != 0 ) throw exception::CommonException ( "Dot: Failed to initialize communication pipe." ); pid_t pid = fork ( ); @@ -31,14 +31,17 @@ void Dot::run ( const std::string & data, const std::string & outputType, const close ( fd [ 0 ] ); close ( fd [ 1 ] ); - const char* cmd [ 6 ] = { "dot", "-T", outputType.c_str ( ), nullptr }; + std::vector < const char * > cmd; + cmd.push_back ( "dot" ); + cmd.push_back ( "-T" ); + cmd.push_back ( outputType.c_str ( ) ); if ( outputFile.has_value ( ) ) { - cmd [ 3 ] = "-o"; - cmd [ 4 ] = outputFile->c_str ( ); - cmd [ 5 ] = nullptr; + cmd.push_back ( "-o" ); + cmd.push_back ( outputFile->c_str ( ) ); } + cmd.push_back ( nullptr ); - if ( execvp ( "dot", const_cast < char* const* > ( cmd ) ) == -1 ) // I do not like the const_cast but this is a real issue when mixing C with C++ + if ( execvp ( "dot", const_cast < char* const* > ( cmd.data ( ) ) ) == -1 ) // I do not like the const_cast but this is a real issue when mixing C with C++ throw exception::CommonException ( "Dot: Failed to spawn child process." ); } else { close ( fd [ 0 ] );