Skip to content

ARM32 Architecture: Bus Error When Converting Vector of Packed Structures to JSON #4687

Open
@sbhutch

Description

@sbhutch

Description

Converting a vector of packed structures to JSON produces a bus error on arm32v7 architectures.

Reproduction steps

A minimal code example is provided below, this program features a packed structure that is not 4-byte-aligned. The program creates a vector of packed structures and attempts to convert to json via a user defined conversion function. The program was cross-compiled for a 32-bit arm system. Executing the program on said system produces a bus error during the conversion process.

Expected vs. actual results

The program should convert the vector of packed structures to JSON and print the result. A bus error occurs during the process.

Minimal code example

#include <nlohmann/json.hpp>

#include <iostream>
#include <vector>

#pragma pack(push, 1)
struct Foo {
    double bar1;
    char bar2;
};
#pragma pack(pop)

void to_json(nlohmann::json& json, const Foo& foo)
{
    json = {
        { "bar1", foo.bar1 },
        { "bar2", foo.bar2 },
    };
}

int main()
{
    std::vector<Foo> foos {
        { 1.0, 1 },
        { 2.0, 2 },
    };

    nlohmann::json json = foos;

    std::cout << json << "\n";
}

Error messages

$ ./json_test 
Bus error

Compiler and operating system

Cross compiled via arm-linux-gnueabihf-g++ for arm32v7 architecture, all systems running Ubuntu 24.04.

Library version

3.11.3

Validation

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind: bugstate: stalethe issue has not been updated in a while and will be closed automatically soon unless it is updated

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions