Skip to content

[Segfault] Passing array to execute() triggers runtime crash due to unsafe padding #1690

@ayush4874

Description

@ayush4874

Description

Passing a raw array (e.g., double grads[2]) to grad.execute(...) causes a segmentation fault at runtime.

It seems execute_with_default_args fails to unpack the array into individual pointers. Instead of detecting the argument count mismatch, it assumes the remaining arguments are missing and pads them with nullptr. The generated gradient code then attempts to write to these null addresses.

Reproduction

#include "clad/Differentiator/Differentiator.h"

double foo(double x, double y) { return x * y; }

int main() {
    auto grad = clad::gradient(foo);
    double x = 3.0, y = 4.0;
    
    // This triggers the crash
    double grads[2] = {0, 0};
    grad.execute(x, y, grads); 
    
    return 0;
}

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