11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci// Tests that passing a negative offset does not crash the process
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciconst common = require('../common');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst {
81cb0ef41Sopenharmony_ci  join,
91cb0ef41Sopenharmony_ci} = require('path');
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst {
121cb0ef41Sopenharmony_ci  closeSync,
131cb0ef41Sopenharmony_ci  open,
141cb0ef41Sopenharmony_ci  write,
151cb0ef41Sopenharmony_ci  writeSync,
161cb0ef41Sopenharmony_ci} = require('fs');
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ciconst assert = require('assert');
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir');
211cb0ef41Sopenharmony_citmpdir.refresh();
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ciconst filename = join(tmpdir.path, 'test.txt');
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ciopen(filename, 'w+', common.mustSucceed((fd) => {
261cb0ef41Sopenharmony_ci  assert.throws(() => {
271cb0ef41Sopenharmony_ci    write(fd, Buffer.alloc(0), -1, common.mustNotCall());
281cb0ef41Sopenharmony_ci  }, {
291cb0ef41Sopenharmony_ci    code: 'ERR_OUT_OF_RANGE',
301cb0ef41Sopenharmony_ci  });
311cb0ef41Sopenharmony_ci  assert.throws(() => {
321cb0ef41Sopenharmony_ci    writeSync(fd, Buffer.alloc(0), -1);
331cb0ef41Sopenharmony_ci  }, {
341cb0ef41Sopenharmony_ci    code: 'ERR_OUT_OF_RANGE',
351cb0ef41Sopenharmony_ci  });
361cb0ef41Sopenharmony_ci  closeSync(fd);
371cb0ef41Sopenharmony_ci}));
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ciconst filename2 = join(tmpdir.path, 'test2.txt');
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci// Make sure negative length's don't cause aborts either
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ciopen(filename2, 'w+', common.mustSucceed((fd) => {
441cb0ef41Sopenharmony_ci  assert.throws(() => {
451cb0ef41Sopenharmony_ci    write(fd, Buffer.alloc(0), 0, -1, common.mustNotCall());
461cb0ef41Sopenharmony_ci  }, {
471cb0ef41Sopenharmony_ci    code: 'ERR_OUT_OF_RANGE',
481cb0ef41Sopenharmony_ci  });
491cb0ef41Sopenharmony_ci  assert.throws(() => {
501cb0ef41Sopenharmony_ci    writeSync(fd, Buffer.alloc(0), 0, -1);
511cb0ef41Sopenharmony_ci  }, {
521cb0ef41Sopenharmony_ci    code: 'ERR_OUT_OF_RANGE',
531cb0ef41Sopenharmony_ci  });
541cb0ef41Sopenharmony_ci  closeSync(fd);
551cb0ef41Sopenharmony_ci}));
56