@@ -16,19 +16,17 @@ std::vector<long> parse_massif(const std::string& file_path) {
1616
1717 const char equal{' =' };
1818 std::string buffer;
19- while (getline (file, buffer)) {
19+ while (std:: getline (file, buffer)) {
2020 if (buffer.find (" mem_heap_B" ) != std::string::npos) {
2121 std::stringstream buffer_stream (buffer);
2222 std::string value;
23- getline (buffer_stream, value, equal);
23+ std:: getline (buffer_stream, value, equal);
2424 if (value == " mem_heap_B" ) {
25- getline (buffer_stream, value);
25+ std:: getline (buffer_stream, value);
2626 mem_values.push_back (std::stol (value));
2727 }
2828 }
2929 }
30-
31- file.close ();
3230 return mem_values;
3331};
3432
@@ -39,7 +37,12 @@ int main(int argc, char* argv[]) {
3937 }
4038
4139 auto mem_values{parse_massif (argv[1 ])};
42- long long int integral{std::accumulate (mem_values.begin (), mem_values.end (), 0 )};
40+ if (mem_values.empty ()) {
41+ std::cerr << " No mem_heap_B values found in file: " << argv[1 ] << ' \n ' ;
42+ return 1 ;
43+ }
44+
45+ long long integral{std::accumulate (mem_values.begin (), mem_values.end (), 0LL )};
4346 long max_mem{*std::max_element (mem_values.begin (), mem_values.end ())};
4447
4548 std::cout << " integral: " << integral << " B\n " ;
0 commit comments