Skip to content

RB_GC_GUARD() is called on unintialized variables in BigDecimal_DoDivmod() #535

@eregon

Description

@eregon

These 3 calls:

RB_GC_GUARD(dv.bigdecimal);
RB_GC_GUARD(md.bigdecimal);
RB_GC_GUARD(res.bigdecimal);

call RB_GC_GUARD() on variables which might be uninitialized and so contain garbage values.

This seems to apparently work fine on CRuby, but reading the docs I am not sure it is a correct usage.
It seems unusual to do this.

On TruffleRuby this caused transient errors: truffleruby/truffleruby#4274
Probably this is something we can improve in TruffleRuby, OTOH this is I think the first extension we notice doing this.

Given the code is just:

Done:
RB_GC_GUARD(a.bigdecimal);
RB_GC_GUARD(b.bigdecimal);
RB_GC_GUARD(dv.bigdecimal);
RB_GC_GUARD(md.bigdecimal);
RB_GC_GUARD(res.bigdecimal);
return true;

One fix would be to replace goto Done; with the guard + return true, but omit the guards for unitialized variables at that point.
Or, the variables could be always initialized.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions