Skip to content

Commit 17afa55

Browse files
committed
fix(runtime): address PR review and apply safety enhancements
- Replace reserve+operator[] with reserve+emplace_back to avoid UB and double initialization. - Use 1ULL instead of static_cast for bitshifts to align with codebase style. - Add nullptr guards for getenv('HOME') across REST helpers. - Fix local mutex issue in REST helpers by making them static. - Remove double close in IQMServerHelper. - Add exception logging in NVQIR noise tracer. Signed-off-by: Dr Chamyoung 医者 <alokads06@gmail.com>
1 parent 356a3bc commit 17afa55

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

runtime/nvqir/NVQIR.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ constexpr std::string_view typeName() {
222222
template <SimPrecisionType To, SimPrecisionType From>
223223
std::unique_ptr<std::complex<To>[]> convertToComplex(std::complex<From> *data,
224224
std::size_t numQubits) {
225-
auto size = static_cast<std::size_t>(1) << numQubits;
225+
auto size = 1ULL << numQubits;
226226
constexpr auto toType = typeName<To>();
227227
constexpr auto fromType = typeName<From>();
228228
CUDAQ_INFO("copying {} complex<{}> values to complex<{}>", size, fromType,
@@ -240,7 +240,7 @@ std::unique_ptr<std::complex<To>[]> convertToComplex(std::complex<From> *data,
240240
template <SimPrecisionType To, SimPrecisionType From>
241241
std::unique_ptr<std::complex<To>[]> convertToComplex(From *data,
242242
std::size_t numQubits) {
243-
auto size = static_cast<std::size_t>(1) << numQubits;
243+
auto size = 1ULL << numQubits;
244244
constexpr auto toType = typeName<To>();
245245
constexpr auto fromType = typeName<From>();
246246
CUDAQ_INFO("copying {} {} values to complex<{}>", size, fromType, toType);
@@ -979,10 +979,9 @@ std::vector<details::FakeQubit> *
979979
__quantum__qis__convert_array_to_stdvector(Array *arr) {
980980
const std::size_t size = arr->size();
981981
std::vector<details::FakeQubit> *result = new std::vector<details::FakeQubit>;
982-
result->resize(size);
982+
result->reserve(size);
983983
for (std::size_t i = 0; i < size; ++i) {
984-
(*result)[i].id = (*arr)[i];
985-
(*result)[i].negated = false;
984+
result->emplace_back(details::FakeQubit{(*arr)[i], false});
986985
}
987986
return result;
988987
}

0 commit comments

Comments
 (0)