Skip to content

Commit aa5b05f

Browse files
authored
FPGA: Address Coverity issues (#1473)
This PR addresses the Coverity issues flagged on the FPGA part of the code samples.
1 parent 4563957 commit aa5b05f

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

DirectProgramming/C++SYCL_FPGA/ReferenceDesigns/db/src/dbdata.cpp

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -820,8 +820,14 @@ void Database::PrintQ1(std::array<DBDecimal, 3 * 2>& sum_qty,
820820
std::cout << "l|l|sum_qty|sum_base_price|sum_disc_price|"
821821
"sum_charge|avg_qty|avg_price|avg_disc|count_order\n";
822822

823-
// print the results
823+
// Copy old state of cout
824+
std::ios oldState(nullptr);
825+
oldState.copyfmt(std::cout);
826+
827+
// Edit the output format of cout
824828
std::cout << std::fixed << std::setprecision(2);
829+
830+
// print the results
825831
for (int ls_idx = 0; ls_idx < 2; ls_idx++) {
826832
for (int rf_idx = 0; rf_idx < 3; rf_idx++) {
827833
int i = ls_idx * 3 + rf_idx;
@@ -833,6 +839,9 @@ void Database::PrintQ1(std::array<DBDecimal, 3 * 2>& sum_qty,
833839
<< (double)(avg_discount[i]) / 100.0 << "|" << count[i] << "\n";
834840
}
835841
}
842+
843+
// Restore the output format of cout
844+
std::cout.copyfmt(oldState);
836845
}
837846

838847
//
@@ -878,11 +887,21 @@ void Database::PrintQ9(std::array<DBDecimal, 25 * 2020>& sum_profit) {
878887
// print the header
879888
std::cout << "nation|o_year|sum_profit\n";
880889

881-
// print the results
890+
// Copy old state of cout
891+
std::ios oldState(nullptr);
892+
oldState.copyfmt(std::cout);
893+
894+
// Edit the output format of cout
882895
std::cout << std::fixed << std::setprecision(2);
896+
897+
// print the results
883898
for (int i = 0; i < outrows.size(); i++) {
884899
outrows[i].print();
885900
}
901+
902+
// Restore the output format of cout
903+
std::cout.copyfmt(oldState);
904+
886905
}
887906

888907
//
@@ -893,12 +912,22 @@ void Database::PrintQ11(std::vector<DBIdentifier>& partkeys,
893912
// print the header
894913
std::cout << "ps_partkey|value\n";
895914

896-
// print the results
915+
// Copy old state of cout
916+
std::ios oldState(nullptr);
917+
oldState.copyfmt(std::cout);
918+
919+
// Edit the output format of cout
897920
std::cout << std::fixed << std::setprecision(2);
921+
922+
// print the results
898923
for (int i = 0; i < partkeys.size(); i++) {
899924
std::cout << partkeys[i] << "|" << (double)(partkey_values[i]) / (100.00)
900925
<< "\n";
901926
}
927+
928+
// Restore the output format of cout
929+
std::cout.copyfmt(oldState);
930+
902931
}
903932

904933
//
@@ -910,10 +939,20 @@ void Database::PrintQ12(std::string& SM1, std::string& SM2,
910939
// print the header
911940
std::cout << "l_shipmode|high_line_count|low_line_count\n";
912941

913-
// print the results
942+
// Copy old state of cout
943+
std::ios oldState(nullptr);
944+
oldState.copyfmt(std::cout);
945+
946+
// Edit the output format of cout
914947
std::cout << std::fixed;
948+
949+
// print the results
915950
std::cout << SM1 << "|" << high_line_count[0] << "|" << low_line_count[0]
916951
<< "\n";
917952
std::cout << SM2 << "|" << high_line_count[1] << "|" << low_line_count[1]
918953
<< "\n";
954+
955+
// Restore the output format of cout
956+
std::cout.copyfmt(oldState);
957+
919958
}

DirectProgramming/C++SYCL_FPGA/ReferenceDesigns/gzip/src/CompareGzip.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "CompareGzip.hpp"
2+
#include <sys/stat.h>
23

34
// returns 0 on success, otherwise failure
45
int CompareGzipFiles(
@@ -20,7 +21,9 @@ int CompareGzipFiles(
2021
// Create temporary output filename for gunzip
2122

2223
char tmp_name[] = "/tmp/gzip_fpga.XXXXXX";
24+
mode_t mask = umask(S_IXUSR);
2325
mkstemp(tmp_name);
26+
umask(mask);
2427
std::string outputfile = tmp_name;
2528

2629
//------------------------------------------------------------------

0 commit comments

Comments
 (0)