]> git.kaiwu.me - njs.git/commitdiff
Miscellaneous issues found by Coverity Scan have been fixed.
authorIgor Sysoev <igor@sysoev.ru>
Thu, 24 Mar 2016 14:13:27 +0000 (17:13 +0300)
committerIgor Sysoev <igor@sysoev.ru>
Thu, 24 Mar 2016 14:13:27 +0000 (17:13 +0300)
njs/njs_variable.c
njs/njs_vm.c

index 00e34e32c00c5ef69969ce6fd242c43ed1c8acff..6fc55138ac359d66bd540e1aa18393e73da933d3 100644 (file)
@@ -62,7 +62,7 @@ njs_parser_variable(njs_vm_t *vm, njs_parser_t *parser, nxt_uint_t *level)
     njs_variable_t      *var;
     nxt_lvlhsh_query_t  lhq;
 
-    level = 0;
+    *level = 0;
 
     lhq.key_hash = parser->lexer->key_hash;
     lhq.key = parser->lexer->text;
@@ -90,11 +90,11 @@ njs_parser_variable(njs_vm_t *vm, njs_parser_t *parser, nxt_uint_t *level)
         }
 
         scope = scope->parent;
-        level++;
+        (*level)++;
 
     } while (scope != NULL);
 
-    level = 0;
+    *level = 0;
 
     if (nxt_lvlhsh_find(&vm->variables_hash, &lhq) == NXT_OK) {
         return lhq.value;
index 27b5e7f2584669855172787981f84ff7db904069..92713737134c4d505ce3642d7c2b4b65953ec6d4 100644 (file)
@@ -161,128 +161,128 @@ njs_vmcode_interpreter(njs_vm_t *vm)
     njs_native_frame_t    *previous;
     njs_vmcode_generic_t  *vmcode;
 
+    start:
+
     for ( ;; ) {
 
-    again:
-        for ( ;; ) {
+        vmcode = (njs_vmcode_generic_t *) vm->current;
 
-            vmcode = (njs_vmcode_generic_t *) vm->current;
+        /*
+         * The first operand is passed as is in value2 to
+         *   njs_vmcode_jump(),
+         *   njs_vmcode_if_true_jump(),
+         *   njs_vmcode_if_false_jump(),
+         *   njs_vmcode_validate(),
+         *   njs_vmcode_function_frame(),
+         *   njs_vmcode_function_call(),
+         *   njs_vmcode_return(),
+         *   njs_vmcode_try_start(),
+         *   njs_vmcode_try_next(),
+         *   njs_vmcode_try_end(),
+         *   njs_vmcode_catch().
+         *   njs_vmcode_throw().
+         *   njs_vmcode_stop().
+         */
+        value2 = (njs_value_t *) vmcode->operand1;
+        value1 = NULL;
 
-            /*
-             * The first operand is passed as is in value2 to
-             *   njs_vmcode_jump(),
-             *   njs_vmcode_if_true_jump(),
-             *   njs_vmcode_if_false_jump(),
-             *   njs_vmcode_validate(),
-             *   njs_vmcode_function_frame(),
-             *   njs_vmcode_function_call(),
-             *   njs_vmcode_return(),
-             *   njs_vmcode_try_start(),
-             *   njs_vmcode_try_next(),
-             *   njs_vmcode_try_end(),
-             *   njs_vmcode_catch().
-             *   njs_vmcode_throw().
-             *   njs_vmcode_stop().
-             */
-            value2 = (njs_value_t *) vmcode->operand1;
-            value1 = NULL;
+        switch (vmcode->code.operands) {
 
-            switch (vmcode->code.operands) {
+        case NJS_VMCODE_3OPERANDS:
+            value2 = njs_vmcode_operand(vm, vmcode->operand3);
 
-            case NJS_VMCODE_3OPERANDS:
-                value2 = njs_vmcode_operand(vm, vmcode->operand3);
+            /* Fall through. */
 
-            case NJS_VMCODE_2OPERANDS:
-                value1 = njs_vmcode_operand(vm, vmcode->operand2);
-            }
+        case NJS_VMCODE_2OPERANDS:
+            value1 = njs_vmcode_operand(vm, vmcode->operand2);
+        }
 
-            ret = vmcode->code.operation(vm, value1, value2);
+        ret = vmcode->code.operation(vm, value1, value2);
 
-            /*
-             * On success an operation returns size of the bytecode,
-             * a jump offset or zero after the call or return operations.
-             * Jumps can return a negative offset.  Compilers can generate
-             *    (ret < 0 && ret >= NJS_PREEMPT)
-             * as a single unsigned comparision.
-             */
+        /*
+         * On success an operation returns size of the bytecode,
+         * a jump offset or zero after the call or return operations.
+         * Jumps can return a negative offset.  Compilers can generate
+         *    (ret < 0 && ret >= NJS_PREEMPT)
+         * as a single unsigned comparision.
+         */
 
-            if (nxt_slow_path(ret < 0 && ret >= NJS_PREEMPT)) {
-                break;
-            }
+        if (nxt_slow_path(ret < 0 && ret >= NJS_PREEMPT)) {
+            break;
+        }
 
-            vm->current += ret;
+        vm->current += ret;
 
-            if (vmcode->code.retval) {
-                retval = njs_vmcode_operand(vm, vmcode->operand1);
-                //njs_release(vm, retval);
-                *retval = vm->retval;
-            }
+        if (vmcode->code.retval) {
+            retval = njs_vmcode_operand(vm, vmcode->operand1);
+            //njs_release(vm, retval);
+            *retval = vm->retval;
         }
+    }
 
-        switch (ret) {
+    switch (ret) {
 
-        case NJS_TRAP_NUMBER:
-            value2 = value1;
+    case NJS_TRAP_NUMBER:
+        value2 = value1;
 
-            /* Fall through. */
+        /* Fall through. */
 
-        case NJS_TRAP_NUMBERS:
-        case NJS_TRAP_STRINGS:
-        case NJS_TRAP_INCDEC:
-        case NJS_TRAP_PROPERTY:
+    case NJS_TRAP_NUMBERS:
+    case NJS_TRAP_STRINGS:
+    case NJS_TRAP_INCDEC:
+    case NJS_TRAP_PROPERTY:
 
-            njs_vm_trap(vm, ret - NJS_TRAP_BASE, value1, value2);
+        njs_vm_trap(vm, ret - NJS_TRAP_BASE, value1, value2);
 
-            goto again;
+        goto start;
 
-        case NJS_TRAP_NUMBER_ARG:
-        case NJS_TRAP_STRING_ARG:
+    case NJS_TRAP_NUMBER_ARG:
+    case NJS_TRAP_STRING_ARG:
 
-            ret = njs_vm_trap_argument(vm, ret - NJS_TRAP_BASE);
-            if (nxt_fast_path(ret == NXT_OK)) {
-                goto again;
-            }
+        ret = njs_vm_trap_argument(vm, ret - NJS_TRAP_BASE);
+        if (nxt_fast_path(ret == NXT_OK)) {
+            goto start;
+        }
 
-            break;
+        break;
 
-        default:
-            break;
-        }
+    default:
+        break;
+    }
 
-        if (ret == NXT_ERROR) {
+    if (ret == NXT_ERROR) {
 
-            for ( ;; ) {
-                frame = (njs_frame_t *) vm->frame;
-                catch = frame->native.exception.catch;
+        for ( ;; ) {
+            frame = (njs_frame_t *) vm->frame;
+            catch = frame->native.exception.catch;
 
-                if (catch != NULL) {
-                    vm->current = catch;
-                    goto again;
-                }
+            if (catch != NULL) {
+                vm->current = catch;
+                goto start;
+            }
 
-                previous = frame->native.previous;
-                if (previous == NULL) {
-                    return NXT_ERROR;
-                }
+            previous = frame->native.previous;
+            if (previous == NULL) {
+                return NXT_ERROR;
+            }
 
-                vm->frame = previous;
+            vm->frame = previous;
 
-                /* GC: NJS_SCOPE_ARGUMENTS and NJS_SCOPE_LOCAL. */
+            /* GC: NJS_SCOPE_ARGUMENTS and NJS_SCOPE_LOCAL. */
 
-                vm->scopes[NJS_SCOPE_CALLEE_ARGUMENTS] = previous->arguments;
-                vm->scopes[NJS_SCOPE_LOCAL] = frame->prev_local;
-                vm->scopes[NJS_SCOPE_ARGUMENTS] = frame->prev_arguments;
+            vm->scopes[NJS_SCOPE_CALLEE_ARGUMENTS] = previous->arguments;
+            vm->scopes[NJS_SCOPE_LOCAL] = frame->prev_local;
+            vm->scopes[NJS_SCOPE_ARGUMENTS] = frame->prev_arguments;
 
-                if (frame->native.first) {
-                    nxt_mem_cache_free(vm->mem_cache_pool, frame);
-                }
+            if (frame->native.first) {
+                nxt_mem_cache_free(vm->mem_cache_pool, frame);
             }
         }
+    }
 
-        /* NXT_AGAIN, NJS_STOP. */
+    /* NXT_AGAIN, NJS_STOP. */
 
-        return ret;
-    }
+    return ret;
 }
 
 
@@ -517,6 +517,8 @@ njs_vmcode_property_get(njs_vm_t *vm, njs_value_t *object,
                 prop = pq.lhq.value;
             }
 
+            /* Fall through. */
+
         case NJS_PROPERTY:
             retval = &prop->value;
             break;