79448725

Date: 2025-02-18 15:13:53
Score: 0.5
Natty:
Report link

IDK what the hell happened but this code

    void push_back(const T& elem) {
        try {
            if (capacity <= size) {
                auto newData = normalize_capacity();
                std::memcpy(newData, data, size * sizeof(T));
                if (data != nullptr && newData != data) {
                    free(data);
                }
                data = newData;
            }
            data[size] = elem;
            ++size;
        }
        catch (...) {
            std::cerr << "Something happened in push_back" << std::endl;
            throw;
        }
    }

with this

    T* normalize_capacity() {
        while (capacity <= size) {
            capacity *= 2;
        }
        T* newData = (T*)malloc(sizeof(T) * capacity);
        if (!newData) {
            throw std::bad_alloc();
        }
        if (data) {
            std::memcpy(newData, data, size * sizeof(T));
        }
        return newData;
    }

actually worked thank you guys for all of the help and advises!

Reasons:
  • Blacklisted phrase (0.5): thank you
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: NeKon