Skip to content

Fix uninitialized work->x in daqp_check_unconstrained when no linear term#149

Merged
darnstrom merged 2 commits intomasterfrom
copilot/fix-minrep-uninitialized-variables
Mar 27, 2026
Merged

Fix uninitialized work->x in daqp_check_unconstrained when no linear term#149
darnstrom merged 2 commits intomasterfrom
copilot/fix-minrep-uninitialized-variables

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 27, 2026

daqp_check_unconstrained uses work->xold (malloc'd, uninitialized) as scratch space by swapping it into work->x, then skips writing to it when work->v == NULL (no f term). The subsequent feasibility check reads garbage, causing the unconstrained shortcut to fire incorrectly—or not at all—for pure quadratic problems (min 0.5 x'Hx, no linear term).

When the shortcut fires incorrectly, sing_ind is set to DAQP_UNCONSTRAINED_OPTIMAL and the extracted primal solution is garbage from uninitialized memory. This is the root cause of the erratic minrep behaviour reported after the unconstrained-feasibility shortcut was introduced.

Changes

  • src/utils.c — In daqp_check_unconstrained, add an else branch covering work->v == NULL. The unconstrained optimum of min 0.5 x'Hx is always x = 0, so zero the scratch buffer before the feasibility check:
    if(work->v != NULL){
        /* existing Rinv / RinvD / identity branches */
    } else {
        // No linear term: unconstrained optimum is x = 0
        for(i = 0; i < n; i++) work->x[i] = 0.0;
    }
  • interfaces/daqp-eigen/tests/08_unconstrained_check.cpp — Two new test cases:
    • min 0.5||x||² s.t. -1 ≤ x ≤ 1: x = 0 is feasible → shortcut must return x* = 0
    • min 0.5||x||² s.t. 2 ≤ x ≤ 5: x = 0 violates bounds → shortcut must not fire; solver returns x* = [2, 2]

📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Copilot AI changed the title [WIP] Fix erratic behaviour in minrep function due to uninitialized variables Fix uninitialized work->x in daqp_check_unconstrained when no linear term Mar 27, 2026
Copilot AI requested a review from darnstrom March 27, 2026 20:35
@darnstrom darnstrom marked this pull request as ready for review March 27, 2026 20:42
@darnstrom darnstrom merged commit b277646 into master Mar 27, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants