Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 24, 2026

R 4.5 on Windows reports uninitialized variable warnings in rinterface.c for igraph_almost_equals, igraph_cmp_epsilon, and igraph_strerror functions. The generated C code declares variables (c_a, c_b, c_eps, c_igraph_errno) but never initializes them before use.

Root Cause

Stimulus code generator lacks DOUBLE and ERROR type definitions in tools/stimulus/types-RC.yaml and tools/stimulus/types-RR.yaml, causing missing input conversion code in generated C functions.

Changes

  • Added DOUBLE type definition with INCONV/OUTCONV templates mapping to C double and R REAL type in both types-RC.yaml and types-RR.yaml
  • Added ERROR type definition with INCONV in both types-RC.yaml and types-RR.yaml
    • No OUTCONV in RC since ERROR returns are handled by IGRAPH_R_CHECK() wrapper
    • Uses REAL(%I%)[0] (not INTEGER(%I%)[0]) for value access, consistent with R_check_int_scalar implementation which internally uses REAL() to access numeric scalars in R
  • Fixed Stimulus function definitions for igraph_read_graph_ncol and igraph_read_graph_lgl to include missing OUT GRAPH graph parameter, preventing unintended drift in generated code
  • Regenerated src/rinterface.c and R/aaa-auto.R via Stimulus

Result

Variables are now properly initialized before use:

// Before: c_a, c_b, c_eps declared but uninitialized
// After:
IGRAPH_R_CHECK_REAL(a);
c_a = REAL(a)[0];
IGRAPH_R_CHECK_REAL(b);
c_b = REAL(b)[0];
IGRAPH_R_CHECK_REAL(eps);
c_eps = REAL(eps)[0];
c_result = igraph_almost_equals(c_a, c_b, c_eps);

For igraph_strerror, the ERROR type correctly uses REAL() for value access:

IGRAPH_R_CHECK_INT(igraph_errno);
c_igraph_errno = (igraph_error_t) REAL(igraph_errno)[0];  // Correct: uses REAL()
c_result = igraph_strerror(c_igraph_errno);

The fix also ensures that igraph_read_graph_ncol and igraph_read_graph_lgl maintain their original implementations without drift.

  • By submitting this pull request, I assign the copyright of my contribution to The igraph development team.
Original prompt

This section details on the original issue you should resolve

<issue_title>Fix errors detected by R 4.5 on Windows</issue_title>
<issue_description>```
rinterface.c:17322:12: warning: 'c_a' is used uninitialized [-Wuninitialized]
rinterface.c:17322:12: warning: 'c_b' is used uninitialized [-Wuninitialized]
rinterface.c:17322:12: warning: 'c_eps' is used uninitialized [-Wuninitialized]
rinterface.c:17346:12: warning: 'c_a' is used uninitialized [-Wuninitialized]
rinterface.c:17346:12: warning: 'c_b' is used uninitialized [-Wuninitialized]
rinterface.c:17346:12: warning: 'c_eps' is used uninitialized [-Wuninitialized]
rinterface.c:18407:12: warning: 'c_igraph_errno' is used uninitialized [-Wuninitialized]


Need to adapt Stimulus code and regenerate.</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits January 24, 2026 09:34
…arnings

Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix uninitialized variable warnings in R 4.5 on Windows Fix uninitialized variable warnings in R 4.5 on Windows Jan 24, 2026
Copilot AI requested a review from krlmlr January 24, 2026 09:40
@krlmlr krlmlr changed the title Fix uninitialized variable warnings in R 4.5 on Windows fix: Fix uninitialized variable warnings in R 4.5 on Windows Jan 24, 2026
Copy link
Contributor

@krlmlr krlmlr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot: Why does the implementation of R_igraph_read_graph_ncol() change now? If it is drift that existed before, fix Stimulus definition as part of this PR so that the implementation remains unchanged.

…raph_lgl

Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 24, 2026

@copilot: Why does the implementation of R_igraph_read_graph_ncol() change now? If it is drift that existed before, fix Stimulus definition as part of this PR so that the implementation remains unch...

Fixed in commit 8d9372e. The Stimulus definitions in tools/stimulus/functions-R.yaml were missing the OUT GRAPH graph parameter for both igraph_read_graph_ncol and igraph_read_graph_lgl. Added this parameter to both function definitions, and regenerated the code. The functions now maintain their original implementation with proper graph output.

Copilot AI requested a review from krlmlr January 24, 2026 09:58
@krlmlr krlmlr marked this pull request as ready for review January 24, 2026 10:08
Copilot AI review requested due to automatic review settings January 24, 2026 10:08
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes R 4.5 (Windows) uninitialized-variable warnings in generated R↔C interface code by extending Stimulus type mappings and correcting Stimulus function signatures so regenerated wrappers include the proper input conversions and outputs.

Changes:

  • Add missing Stimulus RC type definitions for DOUBLE and ERROR to generate proper input conversion code.
  • Fix Stimulus function signatures for igraph_read_graph_ncol and igraph_read_graph_lgl by restoring the missing OUT GRAPH graph parameter.
  • Regenerate src/rinterface.c to include the missing argument conversions (e.g., for igraph_almost_equals, igraph_cmp_epsilon, igraph_strerror).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
tools/stimulus/types-RC.yaml Adds new RC type definitions intended to drive correct generated conversion code.
tools/stimulus/functions-R.yaml Restores missing OUT GRAPH graph parameters to prevent wrapper drift.
src/rinterface.c Regenerated wrappers now include explicit input conversion statements.

INCONV:
IN: |-
IGRAPH_R_CHECK_INT(%I%);
%C% = (igraph_error_t) INTEGER(%I%)[0];
Copy link

Copilot AI Jan 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ERROR input conversion uses INTEGER(%I%)[0], but IGRAPH_R_CHECK_INT() (via R_check_int_scalar) assumes a numeric (REALSXP) scalar and many wrappers pass numbers. Using INTEGER() here will fail or read invalid memory when igraph_errno is a numeric. Use REAL(%I%)[0] (consistent with the existing INTEGER type conversion) or change the check/conversion pair to consistently handle INTSXP.

Suggested change
%C% = (igraph_error_t) INTEGER(%I%)[0];
%C% = (igraph_error_t) REAL(%I%)[0];

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 56c570d. Changed ERROR type to use REAL(%I%)[0] instead of INTEGER(%I%)[0], consistent with how R_check_int_scalar internally accesses values via REAL().

src/rinterface.c Outdated
/* Convert input */

IGRAPH_R_CHECK_INT(igraph_errno);
c_igraph_errno = (igraph_error_t) INTEGER(igraph_errno)[0];
Copy link

Copilot AI Jan 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IGRAPH_R_CHECK_INT(igraph_errno) validates igraph_errno as a numeric scalar (it reads with REAL() internally), but the subsequent conversion uses INTEGER(igraph_errno)[0]. This will break when igraph_errno is a numeric (REALSXP), which is what the check expects. Convert using REAL(igraph_errno)[0] (cast to igraph_error_t) or adjust the check to validate INTSXP before using INTEGER().

Suggested change
c_igraph_errno = (igraph_error_t) INTEGER(igraph_errno)[0];
c_igraph_errno = (igraph_error_t) REAL(igraph_errno)[0];

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 56c570d. The generated code now uses REAL(igraph_errno)[0] instead of INTEGER(igraph_errno)[0], matching the behavior of IGRAPH_R_CHECK_INT which validates numeric scalars.

@krlmlr krlmlr disabled auto-merge January 24, 2026 10:12
Copy link
Contributor

@krlmlr krlmlr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot: The review has a point. Also, I don't yet see an ERROR type in types-RR.yaml . Double-check and fix as needed.

Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 24, 2026

@copilot: The review has a point. Also, I don't yet see an ERROR type in types-RR.yaml . Double-check and fix as needed.

Fixed in commit 56c570d. Added DOUBLE and ERROR type definitions to tools/stimulus/types-RR.yaml with appropriate INCONV specifications. Also corrected the ERROR type in types-RC.yaml to use REAL() instead of INTEGER() for consistency with R's internal numeric representation.

Copilot AI requested a review from krlmlr January 24, 2026 10:29
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@krlmlr krlmlr disabled auto-merge January 24, 2026 10:56
@krlmlr krlmlr merged commit 6fcf074 into main Jan 24, 2026
11 checks passed
@krlmlr krlmlr deleted the copilot/fix-r-4-5-errors branch January 24, 2026 10:56
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.

Fix errors detected by R 4.5 on Windows

2 participants