[svn:parrot] r40300 - trunk/src/pmc

chromatic at svn.parrot.org chromatic at svn.parrot.org
Tue Jul 28 07:57:27 UTC 2009


Author: chromatic
Date: Tue Jul 28 07:57:27 2009
New Revision: 40300
URL: https://trac.parrot.org/parrot/changeset/40300

Log:
[PMC] Moved a pointer dereference after the check for its NULLness in
ParrotInterpreter's get_pmc_keyed() vtable entry (Coverity CID #411).

Modified:
   trunk/src/pmc/parrotinterpreter.pmc

Modified: trunk/src/pmc/parrotinterpreter.pmc
==============================================================================
--- trunk/src/pmc/parrotinterpreter.pmc	Tue Jul 28 07:49:48 2009	(r40299)
+++ trunk/src/pmc/parrotinterpreter.pmc	Tue Jul 28 07:57:27 2009	(r40300)
@@ -522,9 +522,7 @@
         s = CONST_STRING(interp, "annotations");
 
         if (Parrot_str_equal(interp, item, s)) {
-            Parrot_sub *sub;
             PMC        *sub_pmc = ctx->current_sub;
-            PMC_get_sub(interp, sub_pmc, sub);
             if (ctx == CONTEXT(interp)) {
                 /* We can't know the current program counter for the currently
                  * executing sub, so can't return annotations for that. */
@@ -532,16 +530,21 @@
                     Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
                             "Cannot get annotations at depth 0; use annotations op instead.");
             }
-            if (!PMC_IS_NULL(sub_pmc) && sub_pmc->vtable->base_type == enum_class_Sub &&
-                    sub->seg->annotations) {
-                PackFile_ByteCode *seg = sub->seg;
-                opcode_t *pc = ctx->current_pc;
-                return PackFile_Annotations_lookup(interp,  seg->annotations,
+            if (!PMC_IS_NULL(sub_pmc)
+            &&   sub_pmc->vtable->base_type == enum_class_Sub) {
+                Parrot_sub        *sub;
+                PackFile_ByteCode *seg;
+                opcode_t          *pc  = ctx->current_pc;
+
+                PMC_get_sub(interp, sub_pmc, sub);
+                seg = sub->seg;
+
+                if (sub->seg->annotations)
+                    return PackFile_Annotations_lookup(interp, seg->annotations,
                         pc - seg->base.data, NULL);
             }
-            else {
-                return pmc_new(interp, enum_class_Hash);
-            }
+
+            return pmc_new(interp, enum_class_Hash);
         }
 
         Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_ATTRIB_NOT_FOUND,


More information about the parrot-commits mailing list