Bladeren bron

CodeQL fixes

Lutz Roeder 3 jaren geleden
bovenliggende
commit
2c4beab8c2

+ 0 - 1
source/acuity.js

@@ -1,6 +1,5 @@
 
 var acuity = acuity || {};
-var json = json || require('./json');
 
 acuity.ModelFactory = class {
 

+ 1 - 1
source/base.js

@@ -350,7 +350,7 @@ base.Utility = class {
                 return result;
             }
             else if (b.equals(base.Int64.min)) {
-                return unsigned ? base.Uint64.zero : base.Int64.zero;
+                return base.Int64.zero;
             }
             if (a.isNegative) {
                 if (b.isNegative) {

+ 1 - 1
source/caffe.js

@@ -112,7 +112,7 @@ caffe.ModelFactory = class {
                         return openNetParameterText(context, file, buffer);
                     }).catch((error) => {
                         if (error) {
-                            const message = error && error.message ? error.message : error.toString();
+                            const message = error.message ? error.message : error.toString();
                             throw new caffe.Error("Failed to load '" + file + "' (" + message.replace(/\.$/, '') + ').');
                         }
                     });

+ 1 - 1
source/coreml.js

@@ -1414,7 +1414,7 @@ coreml.Utility = class {
                     if (type.multiArrayType.shape && type.multiArrayType.shape.length > 0) {
                         shape = new coreml.TensorShape(type.multiArrayType.shape);
                     }
-                    let dataType = '?';
+                    let dataType;
                     const ArrayDataType = coreml.proto.ArrayFeatureType.ArrayDataType;
                     switch (type.multiArrayType.dataType) {
                         case ArrayDataType.INVALID_ARRAY_DATA_TYPE:

+ 1 - 1
source/dagre.js

@@ -876,7 +876,7 @@ dagre.layout = (graph, options) => {
                         }
                     }
                     if (!ascending) {
-                        while (pathIdx < path.length - 1 && g.node(pathV = path[pathIdx + 1]).label.minRank <= node.rank) {
+                        while (pathIdx < path.length - 1 && g.node(path[pathIdx + 1]).label.minRank <= node.rank) {
                             pathIdx++;
                         }
                         pathV = path[pathIdx];

+ 2 - 2
source/electron.js

@@ -306,8 +306,8 @@ host.ElectronHost = class {
     exception(error, fatal) {
         if (this._telemetry && error && error.telemetry !== false) {
             try {
-                const name = error && error.name ? error.name + ': ' : '';
-                const message = error && error.message ? error.message : JSON.stringify(error);
+                const name = error.name ? error.name + ': ' : '';
+                const message = error.message ? error.message : JSON.stringify(error);
                 const description = [ name + message ];
                 if (error.stack) {
                     const format = (file, line, column) => {

+ 0 - 2
source/flatbuffers.js

@@ -1,7 +1,5 @@
 
-
 var flatbuffers = {};
-var json = json || require('./json');
 
 flatbuffers.get = (name) => {
     flatbuffers._map = flatbuffers._map || new Map();

+ 7 - 6
source/index.js

@@ -121,12 +121,12 @@ host.BrowserHost = class {
                         try {
                             const json = JSON.parse(text);
                             const countries = ['AT', 'BE', 'BG', 'HR', 'CZ', 'CY', 'DK', 'EE', 'FI', 'FR', 'DE', 'EL', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'NO', 'PL', 'PT', 'SK', 'ES', 'SE', 'GB', 'UK', 'GR', 'EU', 'RO'];
-                            if (json && json.country && !countries.indexOf(json.country) !== -1) {
-                                this._setCookie('consent', Date.now(), 30);
-                                telemetry();
+                            if (json && json.country && countries.indexOf(json.country) >= 0) {
+                                consent();
                             }
                             else {
-                                consent();
+                                this._setCookie('consent', Date.now(), 30);
+                                telemetry();
                             }
                         }
                         catch (err) {
@@ -366,8 +366,9 @@ host.BrowserHost = class {
 
     exception(error, fatal) {
         if (this._telemetry && this.window.ga && error && error.telemetry !== false) {
-            const description = [];
-            description.push((error && error.name ? (error.name + ': ') : '') + (error && error.message ? error.message : JSON.stringify(error)));
+            const name = error.name ? error.name + ': ' : '';
+            const message = error.message ? error.message : JSON.stringify(error);
+            const description = [ name + message ];
             if (error.stack) {
                 const format = (file, line, column) => {
                     return file.split('\\').join('/').split('/').pop() + ':' + line + ':' + column;

+ 5 - 5
source/mlnet.js

@@ -3,7 +3,6 @@
 
 var mlnet = mlnet || {};
 var base = base || require('./base');
-var zip = zip || require('./zip');
 
 mlnet.ModelFactory = class {
 
@@ -658,14 +657,15 @@ mlnet.BinaryReader = class extends base.BinaryReader {
         if (low == 0xffffffff && hi == 0x7fffffff) {
             return Number.MAX_SAFE_INTEGER;
         }
-        if (hi == -1) {
+        if (hi === 0xffffffff) {
             return -low;
         }
-        if (hi != 0) {
-            throw new mlnet.Error('Value not in 48-bit range.');
+        if (hi !== 0) {
+            throw new mlnet.Error('Value not in 32-bit range.');
         }
-        return (hi << 32) | low;
+        return low;
     }
+
     float32s(count) {
         const values = [];
         for (let i = 0; i < count; i++) {

+ 1 - 3
source/mxnet.js

@@ -1,8 +1,6 @@
 
 var mxnet = mxnet || {};
 var json = json || require('./json');
-var zip = zip || require('./zip');
-var ndarray = ndarray || {};
 var base = base || require('./base');
 
 mxnet.ModelFactory = class {
@@ -173,7 +171,7 @@ mxnet.ModelFactory = class {
                 }
                 if (symbol) {
                     if (!manifest.format) {
-                        const version = convertVersion(symbol && symbol.attrs && symbol.attrs.mxnet_version ? symbol.attrs.mxnet_version : null);
+                        const version = convertVersion(symbol.attrs && symbol.attrs.mxnet_version ? symbol.attrs.mxnet_version : null);
                         manifest.format = 'MXNet' + (version ? ' v' + version : '');
                     }
                     if (symbol.nodes && symbol.nodes.some((node) => node && node.op == 'tvm_op')) {

+ 1 - 1
source/ncnn.js

@@ -164,7 +164,7 @@ ncnn.Graph = class {
                                 shape[i] = value.shift();
                             }
                             const type = new ncnn.TensorType('?', new ncnn.TensorShape(shape));
-                            arg(output, type, null);
+                            arg(output, type);
                         }
                         attributes.delete(key);
                     }

+ 0 - 2
source/pickle.js

@@ -2,8 +2,6 @@
 // Experimental
 
 var pickle = pickle || {};
-var python = python || require('./python');
-var zip = zip || require('./zip');
 
 pickle.ModelFactory = class {
 

+ 1 - 1
source/protobuf.js

@@ -737,7 +737,7 @@ protobuf.TextReader = class {
     }
 
     double() {
-        let value = NaN;
+        let value;
         let token = this._token;
         switch (token) {
             case 'nan': value = NaN; break;

+ 3 - 6
source/python.js

@@ -82,10 +82,7 @@ python.Parser = class {
     }
 
     _statement() {
-
-        let node = this._node();
-
-        node = this._eat('id', 'break');
+        let node = this._eat('id', 'break');
         if (node) {
             return node;
         }
@@ -2152,7 +2149,7 @@ python.Execution = class {
                 this.feature_names = list('feature_names', this.max_feature_idx + 1);
                 this.feature_infos = list('feature_infos', this.max_feature_idx + 1);
                 if (key_vals.has('monotone_constraints')) {
-                    this.monotone_constraints = list('monotone_constraints', this.max_feature_idx + 1, true);
+                    this.monotone_constraints = list('monotone_constraints', this.max_feature_idx + 1);
                 }
                 if (key_vals.has('objective')) {
                     this.objective = key_vals.get('objective');
@@ -4584,7 +4581,7 @@ python.Execution = class {
                         if (buffer[6] !== 0 && buffer[7] !== 0) {
                             throw new python.Error('Unsigned 64-bit value exceeds 32-bit range.');
                         }
-                        return buffer[0] + (buffer[1] << 8) + (buffer[2] << 16) + (buffer[3] << 24) + (buffer[4] << 32) + (buffer[5] << 40);
+                        return buffer[0] + (buffer[1] << 8) + (buffer[2] << 16) + (buffer[3] << 24) + (buffer[4] * 4294967296) + (buffer[5] * 1099511627776);
                     };
                     for (let i = 0; i < num_tensors; i++) {
                         const args = unpickler.load();

+ 1 - 1
source/pytorch.js

@@ -2595,7 +2595,7 @@ pytorch.Utility = class {
             }
             root = obj;
         }
-        const keys = root && !Array.isArray(root) ? Object.keys(root) : [];
+        const keys = !Array.isArray(root) ? Object.keys(root) : [];
         if (keys.length > 1) {
             keys.splice(0, keys.length);
         }

+ 1 - 1
source/rknn.js

@@ -601,7 +601,7 @@ rknn.Container = class {
                     }
                     this._next = new rknn.Container(stream, data_size);
                     this._next.read();
-                    const value_size = uint64(stream);
+                    const value_size = uint64();
                     this._value = stream.read(value_size);
                     break;
                 }

+ 1 - 2
source/tf.js

@@ -4,7 +4,6 @@
 var tf = tf || {};
 var base = base || require('./base');
 var gzip = gzip || require('./gzip');
-var json = json || require('./json');
 var protobuf = protobuf || require('./protobuf');
 
 tf.ModelFactory = class {
@@ -447,7 +446,7 @@ tf.ModelFactory = class {
                                 }
                             }
                         }
-                        return openSavedModel(saved_model, format, producer, null);
+                        return openSavedModel(saved_model, format, producer);
                     };
                     return Promise.all(shards.values()).then((streams) => {
                         for (const key of shards.keys()) {

+ 1 - 1
source/torch.js

@@ -135,7 +135,7 @@ torch.Graph = class {
                     }
                     index++;
                 }
-                inputs = inputs.concat(newInputs);
+                // inputs = inputs.concat(newInputs);
                 for (const newOutput of newOutputs) {
                     outputs.push(newOutput);
                 }

+ 3 - 2
source/view-sidebar.js

@@ -1725,7 +1725,7 @@ sidebar.Tensor = class {
             case 'boolean':
                 return indentation + value.toString();
             case 'string':
-                return indentation + ((value !== null && value !== undefined) ? ('"' + value + '"') : 'null');
+                return indentation + '"' + value + '"';
             case 'number':
                 if (value == Infinity) {
                     return indentation + 'Infinity';
@@ -1932,7 +1932,8 @@ markdown.Generator = class {
     html(source) {
         const tokens = [];
         const links = new Map();
-        this._tokenize(source.replace(/\r\n|\r/g, '\n').replace(/\t/g, '    '), tokens, links, true);
+        source = source.replace(/\r\n|\r/g, '\n').replace(/\t/g, '    ');
+        this._tokenize(source, tokens, links, true);
         this._tokenizeBlock(tokens, links);
         const result = this._render(tokens, true);
         return result;

+ 1 - 1
source/view.js

@@ -2073,7 +2073,7 @@ view.ModelFactoryService = class {
         if (stream) {
             let empty = true;
             let position = 0;
-            while (empty && position < stream.length) {
+            while (position < stream.length) {
                 const buffer = stream.read(Math.min(4096, stream.length - position));
                 position += buffer.length;
                 if (!buffer.every((value) => value === 0x00)) {

+ 0 - 1
source/weka.js

@@ -2,7 +2,6 @@
 // Experimental
 
 var weka = weka || {};
-var json = json || require('./json');
 var java = {};
 
 weka.ModelFactory = class {

+ 2 - 2
source/xml.js

@@ -356,7 +356,7 @@ xml.TextReader = class {
                                 let whitespace = this._whitespace(0);
                                 if (whitespace && (this._char === '"' || this._char === "'")) {
                                     node.value = this._entityValue();
-                                    whitespace = this._whitespace(0);
+                                    this._whitespace(0);
                                 }
                                 else {
                                     if (whitespace && this._match('SYSTEM')) {
@@ -466,7 +466,7 @@ xml.TextReader = class {
                                     notation.publicId = this._pubidLiteral();
                                     if (this._whitespace(0) && (this._char === '"') || this._char === "'") {
                                         notation.systemId = this._systemLiteral();
-                                        whitespace = this._whitespace(0);
+                                        this._whitespace(0);
                                     }
                                 }
                                 this._assert(notation.systemId || notation.publicId);

+ 3 - 3
test/models.js

@@ -312,7 +312,7 @@ class HTMLElement {
     }
 
     get classList() {
-        return new DOMTokenList(this);
+        return new DOMTokenList();
     }
 
     getBBox() {
@@ -483,7 +483,7 @@ const download = (folder, targets, sources) => {
         if (sourceFiles.length > 0) {
             clearLine();
             process.stdout.write('  decompress...\r');
-            const archive = decompress(data, source.split('?').shift().split('/').pop());
+            const archive = decompress(data);
             clearLine();
             for (const name of sourceFiles) {
                 process.stdout.write('  write ' + name + '\r');
@@ -645,7 +645,7 @@ const loadModel = (target, item) => {
                     if (value && value.length > 1000) {
                         value = value.substring(0, 1000) + '...';
                     }
-                    value = value.split('<');
+                    /* value = */ value.split('<');
                 }
                 for (const input of node.inputs) {
                     input.name.toString();