Skip to content
Snippets Groups Projects
Commit 5b802004 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

tidy: replace C arrays with C++ constructs

parent a21b3d71
No related branches found
No related tags found
1 merge request!200clang tidy fixes
......@@ -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 ] );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment