Skip to content

Commit 4252199

Browse files
committed
fix: ensure byte offset is a multiple of data type byte length
--- 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: na - 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 6d57645 commit 4252199

File tree

1 file changed

+6
-1
lines changed
  • lib/node_modules/@stdlib/array/fixed-endian-factory/lib

1 file changed

+6
-1
lines changed

lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli
234234
* @throws {TypeError} if provided only two arguments, the second argument must be a valid argument
235235
* @throws {TypeError} byte offset must be a nonnegative integer
236236
* @throws {RangeError} must provide sufficient memory to accommodate byte offset and view length requirements
237+
* @throws {RangeError} byte offset must be a multiple of the data type size
238+
* @throws {TypeError} view length must be a positive multiple of the data type size
237239
* @returns {TypedArray} typed array instance
238240
*/
239241
function TypedArray() {
@@ -278,6 +280,9 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli
278280
buf = fromArray( new DataView( new ArrayBuffer( arg.length*BYTES_PER_ELEMENT ) ), arg, isLE );
279281
} else if ( isArrayBuffer( arg ) ) {
280282
buf = new DataView( arg );
283+
if ( !isNonNegativeInteger( arg.byteLength/BYTES_PER_ELEMENT ) ) {
284+
throw new RangeError( format( 'invalid argument. ArrayBuffer byte length must be a multiple of %u. Byte length: `%u`.', BYTES_PER_ELEMENT, buf.byteLength ) );
285+
}
281286
} else if ( isObject( arg ) ) {
282287
if ( HAS_ITERATOR_SYMBOL === false ) {
283288
throw new TypeError( format( 'invalid argument. Environment lacks Symbol.iterator support. Must provide a length, ArrayBuffer, typed array, or array-like object. Value: `%s`.', arg ) );
@@ -1046,7 +1051,7 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli
10461051
) {
10471052
// We need to copy source values...
10481053
tmp = [];
1049-
for ( i = 0; i < value.length; i++ ) {
1054+
for ( i = 0; i < N; i++ ) {
10501055
tmp.push( get( value, i ) );
10511056
}
10521057
sbuf = tmp;

0 commit comments

Comments
 (0)