[go: nahoru, domu]

Skip to content

Commit

Permalink
Fix use of deprecated sprintf (#27)
Browse files Browse the repository at this point in the history
* Fix  deprecated sprintf in GTestApproxNums.cpp
  • Loading branch information
faberga committed Jul 14, 2023
1 parent 83046ad commit 17c33b5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/github-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
package_build: [ON, OFF]
hexl: [ON, OFF]
c_compiler: [gcc, clang]
os: [macos-latest, ubuntu-20.04, ubuntu-22.04]
os: [macos-latest, ubuntu-22.04]
include: # Use g++ with gcc only and clang++ with clang only
- c_compiler: gcc
cxx_compiler: g++
Expand Down
12 changes: 10 additions & 2 deletions tests/GTestApproxNums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <algorithm>
#include <complex>

#include <cstdio>

#include <helib/norms.h>
#include <helib/helib.h>
#include <helib/debugging.h>
Expand Down Expand Up @@ -511,10 +513,13 @@ TEST_P(GTestApproxNums, generalOpsWorks)

std::vector<std::complex<double>> tmp_p(p1); // tmp = c1
helib::Ctxt tmp(c1);
sprintf(buffer, "tmp=c1>>=%d", (int)shamt);

EXPECT_TRUE(snprintf(buffer, sizeof(buffer), "tmp=c1>>=%d", (int)shamt) > 0);

rotate(tmp_p,
shamt); // ea.shift(tmp, random amount in [-nSlots/2,nSlots/2])
ea.rotate(tmp, shamt);

if (helib_test::verbose) {
CheckCtxt(tmp, buffer);
}
Expand All @@ -527,12 +532,15 @@ TEST_P(GTestApproxNums, generalOpsWorks)
}
EXPECT_TRUE(ciphertextMatches(ea, secretKey, p2, c2, epsilon));

sprintf(buffer, "c2>>>=%d", (int)rotamt);
EXPECT_TRUE(snprintf(buffer, sizeof(buffer), "c2>>>=%d", (int)rotamt) > 0);

rotate(p2, rotamt); // ea.rotate(c2, random amount in [1-nSlots, nSlots-1])
ea.rotate(c2, rotamt);

if (helib_test::verbose) {
CheckCtxt(c2, buffer);
}

EXPECT_TRUE(ciphertextMatches(ea, secretKey, p2, c2, epsilon));

negateVec(p1); // c1.negate()
Expand Down
4 changes: 2 additions & 2 deletions tests/GTestGeneral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ TEST_P(GTestGeneral, correctlyImplementsMixOfOperationsOverFourCiphertexts)

helib::PtxtArray tmp_p(p1); // tmp = c1
helib::Ctxt tmp(c1);
sprintf(buffer, "tmp=c1>>=%d", (int)shamt);
EXPECT_TRUE(snprintf(buffer, sizeof(buffer), "tmp=c1>>=%d", (int)shamt) > 0);
shift(tmp_p, shamt); // ea.shift(tmp, random amount in [-nSlots/2,nSlots/2])
ea.shift(tmp, shamt);
if (!helib_test::noPrint)
Expand All @@ -328,7 +328,7 @@ TEST_P(GTestGeneral, correctlyImplementsMixOfOperationsOverFourCiphertexts)
CheckCtxt(c2, "c2+=tmp");
EXPECT_TRUE(ciphertextMatches(ea, secretKey, p2, c2));

sprintf(buffer, "c2>>>=%d", (int)rotamt);
EXPECT_TRUE(snprintf(buffer, sizeof(buffer), "c2>>>=%d", (int)rotamt) > 0);
rotate(p2, rotamt); // ea.rotate(c2, random amount in [1-nSlots, nSlots-1])
ea.rotate(c2, rotamt);
if (!helib_test::noPrint)
Expand Down

0 comments on commit 17c33b5

Please sign in to comment.