Skip to content

[BUG] unsigned int is too small for bytes defined at GadgetUtils/GadgetUtils.h:643 #5

Description

@HelloGithubC

Hello,

I have run a N-body by your code with npar=800^3 and obtained a Segmentation fault. I found the problem with gdb that the bytes you defined to contain pos of particles to write is defiened as unsigned int, which is too small even though I use npar=800^3(800^3*3*sizeof(float) > 2^32-1).

Attach the code in GadgetUtils/GadgetUtils.h:
unsigned int bytes = ntowrite * NDIM * sizeof(float);
buffer = std::vector(bytes);

            // If particles have family then sort POS of them by family in the buffer
            if constexpr (FML::PARTICLE::has_get_pos<T>()) {
                bytes = ntowrite * NDIM * sizeof(float);
                buffer.resize(bytes);
                float_buffer = reinterpret_cast<float *>(buffer.data());
                size_t count = 0;
                for (int curfamily = 0; curfamily < 6; curfamily++) {
                    if (npart_family[curfamily] > 0) {
                        for (size_t j = 0; j < ntowrite; j++) {
                            auto * pos = FML::PARTICLE::GetPos(part[j]);
                            if constexpr (FML::PARTICLE::has_get_family<T>()) {
                                auto family = FML::PARTICLE::GetFamily(part[j]);
                                if (family == curfamily) {
                                    for (int idim = 0; idim < NDIM; idim++)
                                        float_buffer[NDIM * count + idim] = float(pos[idim]) * pos_norm;
                                    count++;
                                }
                            } else {
                                for (int idim = 0; idim < NDIM; idim++)
                                    float_buffer[NDIM * count + idim] = float(pos[idim]) * pos_norm;
                                count++;
                            }
                        }
                    }
                }
                assert(count == ntowrite);
                write_section(fp, buffer, bytes);
            }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions