fatfs
fatfs copied to clipboard
Execution continues even after EBADF
For fs.read
and fs.write
, execution continues even after S.err.EBADF
is called:
fs.write = function write(fd, buf, off, len, pos, cb, _n_) {
cb = GROUP(cb, function () {
var _fd = fileDescriptors[fd];
if (!_fd || !_fd.flags.write) _.delayedCall(cb, S.err.EBADF());
// execution continues
Whereas the function should return once it is determined to have a bad fd
:
fs.write = function write(fd, buf, off, len, pos, cb, _n_) {
cb = GROUP(cb, function () {
var _fd = fileDescriptors[fd];
if (!_fd || !_fd.flags.write) return _.delayedCall(cb, S.err.EBADF());
In general, all of the if (!_fd...
calls could just return, eliminating the need for the else
statements in the other functions as well, so instead of:
if (!_fd || !_fd.flags.read) _.delayedCall(cb, S.err.EBADF());
else {
Just:
if (!_fd || !_fd.flags.read) return _.delayedCall(cb, S.err.EBADF());
which makes for cleaner "less-nested" code.