From 1ce1d529e2674294586ef8074bc322a15110f032 Mon Sep 17 00:00:00 2001 From: Vladimir Petko Date: Tue, 9 Jul 2024 11:32:28 +1200 Subject: [PATCH] BamWriter: use sizeof(uint32_t) increment to swap bytes for big endian architectures. Closes: https://github.com/pezmaster31/bamtools/pull/236 --- src/api/internal/bam/BamWriter_p.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/api/internal/bam/BamWriter_p.cpp b/src/api/internal/bam/BamWriter_p.cpp index 0e81439..70d9bb2 100644 --- a/src/api/internal/bam/BamWriter_p.cpp +++ b/src/api/internal/bam/BamWriter_p.cpp @@ -349,7 +349,7 @@ void BamWriterPrivate::WriteAlignment(const BamAlignment& al) char* cigarData = new char[packedCigarLength](); std::memcpy(cigarData, packedCigar.data(), packedCigarLength); if (m_isBigEndian) { - for (size_t i = 0; i < packedCigarLength; ++i) { + for (size_t i = 0; i < packedCigarLength; i += sizeof(uint32_t)) { BamTools::SwapEndian_32p(&cigarData[i]); } } @@ -500,8 +500,7 @@ void BamWriterPrivate::WriteAlignment(const BamAlignment& al) char* cigarData = new char[packedCigarLength](); std::memcpy(cigarData, packedCigar.data(), packedCigarLength); if (m_isBigEndian) { - for (size_t i = 0; i < packedCigarLength; - ++i) { // FIXME: similarly, this should be "i += 4", not "++i" + for (size_t i = 0; i < packedCigarLength; i += sizeof(uint32_t)) { BamTools::SwapEndian_32p(&cigarData[i]); } }