trying to fix big endian case

This commit is contained in:
Tom Vercauteren 2024-02-20 10:39:19 +00:00
parent f575bbc921
commit b43484b55c
4 changed files with 42 additions and 1 deletions

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.22)
cmake_minimum_required(VERSION 3.16)
project(base64)
set(CMAKE_CXX_STANDARD 17)

View File

@ -598,9 +598,16 @@ inline OutputBuffer decode_into(std::string_view base64Text) {
const std::array<char, 4> tempBytes =
detail::bit_cast<std::array<char, 4>, uint32_t>(temp);
#if defined(__LITTLE_ENDIAN__)
*currDecoding++ = tempBytes[0];
*currDecoding++ = tempBytes[1];
*currDecoding++ = tempBytes[2];
#else
// TODO fix decoding table to avoid the #if here?
*currDecoding++ = tempBytes[1];
*currDecoding++ = tempBytes[2];
*currDecoding++ = tempBytes[3];
#endif
}
switch (numPadding) {
@ -625,8 +632,14 @@ inline OutputBuffer decode_into(std::string_view base64Text) {
const std::array<char, 4> tempBytes =
detail::bit_cast<std::array<char, 4>, uint32_t>(temp);
#if defined(__LITTLE_ENDIAN__)
*currDecoding++ = tempBytes[0];
*currDecoding++ = tempBytes[1];
#else
// TODO fix decoding table to avoid the #if here?
*currDecoding++ = tempBytes[1];
*currDecoding++ = tempBytes[2];
#endif
break;
}
case 2: {
@ -645,7 +658,12 @@ inline OutputBuffer decode_into(std::string_view base64Text) {
const std::array<char, 4> tempBytes =
detail::bit_cast<std::array<char, 4>, uint32_t>(temp);
#if defined(__LITTLE_ENDIAN__)
*currDecoding++ = tempBytes[0];
#else
// TODO fix decoding table to avoid the #if here?
*currDecoding++ = tempBytes[1];
#endif
break;
}
default: {

15
scripts/run-s390x-emulation.sh Executable file
View File

@ -0,0 +1,15 @@
#!/usr/bin/env sh
#
#docker run --rm --privileged multiarch/qemu-user-static:register --reset
docker run -it multiarch/ubuntu-core:s390x-focal /bin/bash
apt-get update -q -y && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends make cmake g++ git
#software-properties-common
cd home
git clone https://github.com/tvercaut/base64.git
cd base64
git checkout modpb64xover
cmake -B ./build -DCMAKE_BUILD_TYPE=Debug .
cmake --build ./build --config Debug
cd build
ctest -C Debug --output-on-failure

View File

@ -12,6 +12,14 @@ int runtests() {
<< (std::is_signed<char>::value ? "signed" : "unsigned")
<< std::endl;
std::cout << "endianness is "
#if defined(__LITTLE_ENDIAN__)
<< "little endian"
#else
<< "big endian"
#endif
<< std::endl;
for (auto& length : lengths) {
std::string original;
for (int i = 0; i < length; i++) {