Skip to content

Commit 71a48b0

Browse files
committed
refactor: guard against null and undefined input values
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 990705b commit 71a48b0

File tree

2 files changed

+19
-6
lines changed
  • lib/node_modules/@stdlib/ndarray/base/dtype-alignment

2 files changed

+19
-6
lines changed

lib/node_modules/@stdlib/ndarray/base/dtype-alignment/lib/main.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,14 @@ function dtypeAlignment( dtype ) {
6161
if ( TABLE === void 0 ) {
6262
TABLE = table();
6363
}
64-
v = dtype.alignment;
65-
if ( isPositiveInteger( v ) ) {
66-
return v;
64+
if ( dtype ) {
65+
v = dtype.alignment;
66+
if ( isPositiveInteger( v ) ) {
67+
return v;
68+
}
69+
return TABLE[ resolve( dtype ) ] || null;
6770
}
68-
return TABLE[ resolve( dtype ) ] || null;
71+
return null;
6972
}
7073

7174

lib/node_modules/@stdlib/ndarray/base/dtype-alignment/test/test.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,17 @@ tape( 'the function returns the alignment for an underlying array data type', fu
124124
});
125125

126126
tape( 'the function returns `null` if provided an unknown/unsupported data type', function test( t ) {
127-
var out = dtypeAlignment( 'foobar' );
128-
t.strictEqual( out, null, 'returns expected value' );
127+
var values;
128+
var out;
129+
var i;
130+
131+
values = [
132+
'foobar',
133+
null
134+
];
135+
for ( i = 0; i < values.length; i++ ) {
136+
out = dtypeAlignment( values[ i ] );
137+
t.strictEqual( out, null, 'returns expected value when provided '+values[ i ] );
138+
}
129139
t.end();
130140
});

0 commit comments

Comments
 (0)