3030#endif
3131
3232ThreadExecutor::ThreadExecutor (const std::vector<std::string> &filenames, const Settings &settings, ErrorLogger &errorLogger)
33- : _filenames(filenames), _settings(settings), _errorLogger(errorLogger), _fileCount(0 )
33+ : _filenames(filenames), _settings(settings), _errorLogger(errorLogger), _fileCount(0 )
3434{
3535
3636}
@@ -49,49 +49,49 @@ ThreadExecutor::~ThreadExecutor()
4949bool ThreadExecutor::handleRead (unsigned int &result)
5050{
5151 char type = 0 ;
52- if (read (_pipe[0 ], &type, 1 ) <= 0 )
52+ if (read (_pipe[0 ], &type, 1 ) <= 0 )
5353 {
5454 return false ;
5555 }
5656
57- if (type != ' 1' && type != ' 2' && type != ' 3' )
57+ if (type != ' 1' && type != ' 2' && type != ' 3' )
5858 {
5959 std::cerr << " #### You found a bug from cppcheck.\n ThreadExecutor::handleRead error, type was:" << type << std::endl;
6060 exit (0 );
6161 }
6262
6363 unsigned int len = 0 ;
64- if (read (_pipe[0 ], &len, sizeof (len)) <= 0 )
64+ if (read (_pipe[0 ], &len, sizeof (len)) <= 0 )
6565 {
6666 std::cerr << " #### You found a bug from cppcheck.\n ThreadExecutor::handleRead error, type was:" << type << std::endl;
6767 exit (0 );
6868 }
6969
7070 char *buf = new char [len];
71- if (read (_pipe[0 ], buf, len) <= 0 )
71+ if (read (_pipe[0 ], buf, len) <= 0 )
7272 {
7373 std::cerr << " #### You found a bug from cppcheck.\n ThreadExecutor::handleRead error, type was:" << type << std::endl;
7474 exit (0 );
7575 }
7676
77- if (type == ' 1' )
77+ if (type == ' 1' )
7878 {
7979 _errorLogger.reportOut (buf);
8080 }
81- else if (type == ' 2' )
81+ else if (type == ' 2' )
8282 {
8383 ErrorLogger::ErrorMessage msg;
8484 msg.deserialize (buf);
8585
8686 // Alert only about unique errors
8787 std::string errmsg = msg.toText ();
88- if (std::find (_errorList.begin (), _errorList.end (), errmsg) == _errorList.end ())
88+ if (std::find (_errorList.begin (), _errorList.end (), errmsg) == _errorList.end ())
8989 {
9090 _errorList.push_back (errmsg);
9191 _errorLogger.reportErr (msg);
9292 }
9393 }
94- else if (type == ' 3' )
94+ else if (type == ' 3' )
9595 {
9696 _fileCount++;
9797 std::istringstream iss (buf);
@@ -109,32 +109,32 @@ unsigned int ThreadExecutor::check()
109109{
110110 _fileCount = 0 ;
111111 unsigned int result = 0 ;
112- if (pipe (_pipe) == -1 )
112+ if (pipe (_pipe) == -1 )
113113 {
114114 perror (" pipe" );
115115 exit (1 );
116116 }
117117
118118 int flags = 0 ;
119- if ((flags = fcntl (_pipe[0 ], F_GETFL, 0 )) < 0 )
119+ if ((flags = fcntl (_pipe[0 ], F_GETFL, 0 )) < 0 )
120120 {
121121 perror (" fcntl" );
122122 exit (1 );
123123 }
124124
125- if (fcntl (_pipe[0 ], F_SETFL, flags | O_NONBLOCK) < 0 )
125+ if (fcntl (_pipe[0 ], F_SETFL, flags | O_NONBLOCK) < 0 )
126126 {
127127 perror (" fcntl" );
128128 exit (1 );
129129 }
130130
131131 unsigned int childCount = 0 ;
132- for (unsigned int i = 0 ; i < _filenames.size (); i++)
132+ for (unsigned int i = 0 ; i < _filenames.size (); i++)
133133 {
134134 // Keep only wanted amount of child processes running at a time.
135- if (childCount >= _settings._jobs )
135+ if (childCount >= _settings._jobs )
136136 {
137- while (handleRead (result))
137+ while (handleRead (result))
138138 {
139139
140140 }
@@ -145,13 +145,13 @@ unsigned int ThreadExecutor::check()
145145 }
146146
147147 pid_t pid = fork ();
148- if (pid < 0 )
148+ if (pid < 0 )
149149 {
150150 // Error
151151 std::cerr << " Failed to create child process" << std::endl;
152152 exit (EXIT_FAILURE);
153153 }
154- else if (pid == 0 )
154+ else if (pid == 0 )
155155 {
156156 CppCheck fileChecker (*this );
157157 fileChecker.settings (_settings);
@@ -166,14 +166,14 @@ unsigned int ThreadExecutor::check()
166166 ++childCount;
167167 }
168168
169- while (childCount > 0 )
169+ while (childCount > 0 )
170170 {
171171 int stat = 0 ;
172172 waitpid (0 , &stat, 0 );
173173 --childCount;
174174 }
175175
176- while (handleRead (result))
176+ while (handleRead (result))
177177 {
178178
179179 }
@@ -188,7 +188,7 @@ void ThreadExecutor::writeToPipe(char type, const std::string &data)
188188 out[0 ] = type;
189189 std::memcpy (&(out[1 ]), &len, sizeof (len));
190190 std::memcpy (&(out[1 +sizeof (len)]), data.c_str (), len);
191- if (write (_pipe[1 ], out, len + 1 + sizeof (len)) <= 0 )
191+ if (write (_pipe[1 ], out, len + 1 + sizeof (len)) <= 0 )
192192 {
193193 delete [] out;
194194 out = 0 ;
0 commit comments