From 28f8664fa1550defcae361ff62e711e71e5727fb Mon Sep 17 00:00:00 2001 From: Marcel Keller Date: Thu, 9 May 2024 15:31:18 +1000 Subject: [PATCH] Fix compilation with clang 18. --- BMR/AndJob.cpp | 3 ++- BMR/network/Node.cpp | 3 ++- Math/Square.hpp | 10 ++++++---- Math/Zp_Data.cpp | 2 +- Networking/sockets.h | 4 ++-- OT/OTVole.hpp | 2 +- Processor/Binary_File_IO.hpp | 4 +++- Protocols/NoShare.h | 3 ++- Protocols/edabit.h | 6 ++++-- Protocols/fake-stuff.hpp | 2 +- Tools/Buffer.cpp | 3 ++- Tools/Buffer.h | 3 ++- Tools/octetStream.cpp | 3 ++- Tools/parse.h | 3 ++- Tools/random.cpp | 3 ++- 15 files changed, 34 insertions(+), 20 deletions(-) diff --git a/BMR/AndJob.cpp b/BMR/AndJob.cpp index 1bf462484..a72542df3 100644 --- a/BMR/AndJob.cpp +++ b/BMR/AndJob.cpp @@ -13,7 +13,7 @@ int AndJob::run() printf("thread %d: run and job from %d to %d with %d gates\n", pthread_self(), start, end, gates.size()); #endif - __m128i prf_output[PAD_TO_8(ProgramParty::s().get_n_parties())]; + __m128i* prf_output = new __m128i[PAD_TO_8(ProgramParty::s().get_n_parties())]; auto gate = gates.begin(); vector< GC::Secret >& S = *this->S; const vector& args = *this->args; @@ -33,5 +33,6 @@ int AndJob::run() gate++; } } + delete[] prf_output; return i_gate; } diff --git a/BMR/network/Node.cpp b/BMR/network/Node.cpp index 0f28914ba..2ab8715cf 100644 --- a/BMR/network/Node.cpp +++ b/BMR/network/Node.cpp @@ -167,7 +167,7 @@ void Node::Broadcast2(SendBuffer& msg) { } void Node::_identify() { - char msg[strlen(ID_HDR)+sizeof(_id)]; + char* msg = new char[strlen(ID_HDR)+sizeof(_id)]; memcpy(msg, ID_HDR, strlen(ID_HDR)); memcpy(msg+strlen(ID_HDR), (const char *)&_id, sizeof(_id)); //printf("Node:: identifying myself:\n"); @@ -178,6 +178,7 @@ void Node::_identify() { phex(buffer.data(), 4); #endif _client->Broadcast(buffer); + delete[] msg; } void Node::_parse_map(const char* netmap_file, int num_parties) { diff --git a/Math/Square.hpp b/Math/Square.hpp index 7ca997eb0..945c18f0b 100644 --- a/Math/Square.hpp +++ b/Math/Square.hpp @@ -5,6 +5,7 @@ #include "Math/Square.h" #include "Math/BitVec.h" +#include "Math/Zp_Data.h" template Square& Square::sub(const Square& other) @@ -83,7 +84,8 @@ void Square::to(U& result) template void Square::to(U& result, true_type) { - int L = U::get_ZpD().get_t(); + int t = U::get_ZpD().get_t(); + const int L = MAX_MOD_SZ; mp_limb_t product[2 * L], sum[2 * L], tmp[L][2 * L]; memset(tmp, 0, sizeof(tmp)); memset(sum, 0, sizeof(sum)); @@ -93,10 +95,10 @@ void Square::to(U& result, true_type) if (i % 64 == 0) memcpy(product, tmp[i/64], sizeof(product)); else - mpn_lshift(product, tmp[i/64], 2 * L, i % 64); - mpn_add_n(sum, product, sum, 2 * L); + mpn_lshift(product, tmp[i/64], 2 * t, i % 64); + mpn_add_n(sum, product, sum, 2 * t); } mp_limb_t q[2 * L], ans[2 * L]; - mpn_tdiv_qr(q, ans, 0, sum, 2 * L, U::get_ZpD().get_prA(), L); + mpn_tdiv_qr(q, ans, 0, sum, 2 * t, U::get_ZpD().get_prA(), t); result.assign((void*) ans); } diff --git a/Math/Zp_Data.cpp b/Math/Zp_Data.cpp index e207d8250..73807c09f 100644 --- a/Math/Zp_Data.cpp +++ b/Math/Zp_Data.cpp @@ -70,7 +70,7 @@ void Zp_Data::init(const bigint& p,bool mont) void Zp_Data::Mont_Mult(mp_limb_t* z,const mp_limb_t* x,const mp_limb_t* y,int t) const { - mp_limb_t ans[2 * MAX_MOD_SZ + 1], u, yy[t + 1]; + mp_limb_t ans[2 * MAX_MOD_SZ + 1], u, yy[MAX_MOD_SZ + 1]; inline_mpn_copyi(yy, y, t); yy[t] = 0; // First loop diff --git a/Networking/sockets.h b/Networking/sockets.h index 6066a393a..4ea85174d 100644 --- a/Networking/sockets.h +++ b/Networking/sockets.h @@ -79,7 +79,7 @@ inline void send(int socket,octet *msg,size_t len) template inline void send(T& socket, size_t a, size_t len) { - octet blen[len]; + octet blen[8]; encode_length(blen, a, len); send(socket, blen, len); } @@ -120,7 +120,7 @@ inline void receive(int socket,octet *msg,size_t len) template inline void receive(T& socket, size_t& a, size_t len) { - octet blen[len]; + octet blen[8]; receive(socket, blen, len); a = decode_length(blen, len); } diff --git a/OT/OTVole.hpp b/OT/OTVole.hpp index f206d613f..4fc737691 100644 --- a/OT/OTVole.hpp +++ b/OT/OTVole.hpp @@ -112,7 +112,7 @@ void OTVoleBase::hash_row(__m128i res[2], const U& row, { auto coeff_base = coefficients; int num_blocks = DIV_CEIL(row.size() * T::size(), 16); - __m128i buffer[T::size()]; + __m128i buffer[T::N_BYTES]; size_t next = 0; while (next + 16 <= row.size()) { diff --git a/Processor/Binary_File_IO.hpp b/Processor/Binary_File_IO.hpp index ea8239a5b..147ea42b0 100644 --- a/Processor/Binary_File_IO.hpp +++ b/Processor/Binary_File_IO.hpp @@ -55,7 +55,7 @@ void Binary_File_IO::read_from_file(const string filename, vector< T >& buffer, int size_in_bytes = T::size() * buffer.size(); int n_read = 0; - char read_buffer[size_in_bytes]; + char* read_buffer = new char[size_in_bytes]; inf.seekg(start_posn * T::size(), iostream::cur); do { @@ -90,4 +90,6 @@ void Binary_File_IO::read_from_file(const string filename, vector< T >& buffer, for (unsigned int i = 0; i < buffer.size(); i++) buffer[i].assign(&read_buffer[i*T::size()]); + + delete[] read_buffer; } diff --git a/Protocols/NoShare.h b/Protocols/NoShare.h index 08fb0c3b4..a8874b8fd 100644 --- a/Protocols/NoShare.h +++ b/Protocols/NoShare.h @@ -170,9 +170,10 @@ class NoShare : public ShareInterface throw runtime_error("no human-readable input"); else { - char buf[size()]; + char* buf = new char[size()]; is.read(buf, size()); assign(buf); + delete[] buf; } } diff --git a/Protocols/edabit.h b/Protocols/edabit.h index d84a0e94c..0ffe780ce 100644 --- a/Protocols/edabit.h +++ b/Protocols/edabit.h @@ -99,7 +99,7 @@ class edabitvec void input(int length, ifstream& s) { - char buffer[MAX_SIZE * T::size()]; + char* buffer = new char[MAX_SIZE * T::size()]; s.read(buffer, MAX_SIZE * T::size()); for (int i = 0; i < MAX_SIZE; i++) { @@ -108,7 +108,7 @@ class edabitvec a.push_back(x); } size_t bsize = T::bit_type::part_type::size(); - char bbuffer[length * bsize]; + char* bbuffer = new char[length * bsize]; s.read(bbuffer, length * bsize); for (int i = 0; i < length; i++) { @@ -116,6 +116,8 @@ class edabitvec x.assign(bbuffer + i * bsize); b.push_back(x); } + delete[] bbuffer; + delete[] buffer; } void output(int length, ofstream& s) diff --git a/Protocols/fake-stuff.hpp b/Protocols/fake-stuff.hpp index f46b3805f..57b5c227a 100644 --- a/Protocols/fake-stuff.hpp +++ b/Protocols/fake-stuff.hpp @@ -93,7 +93,7 @@ void make_vector_share(T* Sa,const U& a,int N,const V& key,PRNG& G) Sa[i].resize_regs(length); for (int j = 0; j < length; j++) { - typename T::part_type shares[N]; + vector shares(N); make_share(shares, typename T::part_type::clear(a.get_bit(j)), N, key, G); for (int i = 0; i < N; i++) Sa[i].get_reg(j) = shares[i]; diff --git a/Tools/Buffer.cpp b/Tools/Buffer.cpp index 8e61aa135..0a20bedb7 100644 --- a/Tools/Buffer.cpp +++ b/Tools/Buffer.cpp @@ -104,7 +104,7 @@ void BufferBase::prune() ofstream tmp(tmp_name.c_str()); size_t start = file->tellg(); start -= element_length() * (BUFFER_SIZE - next); - char buf[header_length]; + char* buf = new char[header_length]; file->seekg(0); file->read(buf, header_length); tmp.write(buf, header_length); @@ -118,6 +118,7 @@ void BufferBase::prune() file->close(); rename(tmp_name.c_str(), filename.c_str()); file->open(filename.c_str(), ios::in | ios::binary); + delete[] buf; } #ifdef VERBOSE else diff --git a/Tools/Buffer.h b/Tools/Buffer.h index d564c64a8..3eb916b57 100644 --- a/Tools/Buffer.h +++ b/Tools/Buffer.h @@ -184,11 +184,12 @@ inline void Buffer::fill_buffer() } else { - char read_buffer[BUFFER_SIZE * T::size()]; + char* read_buffer = new char[BUFFER_SIZE * T::size()]; read(read_buffer); //memset(buffer, 0, sizeof(buffer)); for (int i = 0; i < BUFFER_SIZE; i++) buffer[i].assign(&read_buffer[i*T::size()]); + delete[] read_buffer; } } diff --git a/Tools/octetStream.cpp b/Tools/octetStream.cpp index c36db64a8..b909c7ba8 100644 --- a/Tools/octetStream.cpp +++ b/Tools/octetStream.cpp @@ -106,12 +106,13 @@ octetStream octetStream::hash() const bigint octetStream::check_sum(int req_bytes) const { - unsigned char hash[req_bytes]; + auto hash = new unsigned char[req_bytes]; crypto_generichash(hash, req_bytes, data, len, NULL, 0); bigint ans; bigintFromBytes(ans,hash,req_bytes); // cout << ans << "\n"; + delete[] hash; return ans; } diff --git a/Tools/parse.h b/Tools/parse.h index a9f76f2bb..b4965909f 100644 --- a/Tools/parse.h +++ b/Tools/parse.h @@ -53,9 +53,10 @@ inline void get_vector(int m, vector& start, istream& s) inline void get_string(string& res, istream& s) { unsigned size = get_int(s); - char buf[size]; + char* buf = new char[size]; s.read(buf, size); res.assign(buf, size); + delete[] buf; } #endif /* TOOLS_PARSE_H_ */ diff --git a/Tools/random.cpp b/Tools/random.cpp index 79af3fca1..77a4ad4e0 100644 --- a/Tools/random.cpp +++ b/Tools/random.cpp @@ -241,7 +241,7 @@ void PRNG::get(bigint& res, int n_bits, bool positive) assert(n_bits > 0); int n_bytes = (n_bits + 7) / 8; int n_words = DIV_CEIL(n_bytes, sizeof(word)); - word words[n_words]; + auto words = new word[n_words]; octet* bytes = (octet*) words; words[n_words - 1] = 0; get_octets(bytes, n_bytes); @@ -252,4 +252,5 @@ void PRNG::get(bigint& res, int n_bits, bool positive) mpz_import(res.get_mpz_t(), n_words, -1, sizeof(word), -1, 0, bytes); if (not positive and (get_bit())) mpz_neg(res.get_mpz_t(), res.get_mpz_t()); + delete[] words; }