[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-core
Subject:    Another unitialized variable defect
From:       "Pat Eyler" <rubypate () gmail ! com>
Date:       2006-04-27 14:45:28
Message-ID: 5dc31fed0604270745l3b1cd3admc1ed6448536dc4c7 () mail ! gmail ! com
[Download RAW message or body]

(I hope I'm finally getting the hang of this.)

Another possible defect from Coverity looks like this:

----------------------------------------------------------------------------------------
915     static VALUE
916     BigDecimal_round(int argc, VALUE *argv, VALUE self)
917     {
918         ENTER(5);
919         Real   *c, *a;

Event var_decl: Declared variable "iLoc" without initializer
Also see events: [uninit_use_in_call]

920         int    iLoc;
921         U_LONG mx;
922         VALUE  vLoc;
923         VALUE  vRound;
924         U_LONG pl;
925
926         int    sw = VpGetRoundMode();
927
928         int na = rb_scan_args(argc,argv,"02",&vLoc,&vRound);
929         switch(na) {
930         case 0:
931             iLoc = 0;
932             break;
933         case 1:
934             Check_Type(vLoc, T_FIXNUM);
935             iLoc = FIX2INT(vLoc);
936             break;
937         case 2:
938             Check_Type(vLoc, T_FIXNUM);
939             iLoc = FIX2INT(vLoc);
940             Check_Type(vRound, T_FIXNUM);
941             sw   = FIX2INT(vRound);
942             if(!VpIsRoundMode(sw)) {
943                 rb_raise(rb_eTypeError, "invalid rounding mode");
944                 return Qnil;
945             }
946             break;
947         }
948

At conditional (1): "0" taking true path

949         pl = VpSetPrecLimit(0);
950         GUARD_OBJ(a,GetVpValue(self,1));
951         mx = a->Prec *(VpBaseFig() + 1);
952         GUARD_OBJ(c,VpCreateRbObject(mx, "0"));
953         VpSetPrecLimit(pl);

Event uninit_use_in_call: Using uninitialized value "iLoc" in call to
function "VpActiveRound" [model]
Also see events: [var_decl]

954         VpActiveRound(c,a,sw,iLoc);
955         return ToValue(c);
956     }


----------------------------------------------------------------------------------------


As long as rb_scan_args returns a 0, 1, or 2 everything will be good,
so this is probably a false positive.  Since 0 is a valid value for
na, it could be initialized to zero and any uncertainty avoided:


@@ -917,7 +917,7 @@ BigDecimal_round(int argc, VALUE *argv,
 {
     ENTER(5);
     Real   *c, *a;
-    int    iLoc;
+    int    iLoc = 0;
     U_LONG mx;
     VALUE  vLoc;
     VALUE  vRound;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic