@@ -298,11 +298,13 @@ Buffer.allocUnsafeSlow = function allocUnsafeSlow(size) {
298
298
// If --zero-fill-buffers command line argument is set, a zero-filled
299
299
// buffer is returned.
300
300
function SlowBuffer ( length ) {
301
+ const len = + length ;
301
302
// eslint-disable-next-line eqeqeq
302
- if ( + length != length )
303
+ if ( len != length )
303
304
length = 0 ;
304
- assertSize ( + length ) ;
305
- return createUnsafeBuffer ( + length ) ;
305
+ else
306
+ assertSize ( len ) ;
307
+ return createUnsafeBuffer ( len ) ;
306
308
}
307
309
308
310
Object . setPrototypeOf ( SlowBuffer . prototype , Uint8Array . prototype ) ;
@@ -319,9 +321,8 @@ function allocate(size) {
319
321
poolOffset += size ;
320
322
alignPool ( ) ;
321
323
return b ;
322
- } else {
323
- return createUnsafeBuffer ( size ) ;
324
324
}
325
+ return createUnsafeBuffer ( size ) ;
325
326
}
326
327
327
328
function fromString ( string , encoding ) {
@@ -639,21 +640,18 @@ Buffer.prototype.toString = function toString(encoding, start, end) {
639
640
}
640
641
641
642
const len = this . length ;
642
- if ( len === 0 )
643
- return '' ;
644
643
645
- if ( ! start || start < 0 )
644
+ if ( start <= 0 )
646
645
start = 0 ;
647
646
else if ( start >= len )
648
647
return '' ;
648
+ else
649
+ start |= 0 ;
649
650
650
651
if ( end === undefined || end > len )
651
652
end = len ;
652
- else if ( end <= 0 )
653
- return '' ;
654
-
655
- start |= 0 ;
656
- end |= 0 ;
653
+ else
654
+ end |= 0 ;
657
655
658
656
if ( end <= start )
659
657
return '' ;
@@ -672,10 +670,10 @@ Buffer.prototype.equals = function equals(otherBuffer) {
672
670
} ;
673
671
674
672
// Override how buffers are presented by util.inspect().
675
- Buffer . prototype [ customInspectSymbol ] = function inspect ( ) {
676
- var str = '' ;
677
- var max = exports . INSPECT_MAX_BYTES ;
678
- str = this . toString ( 'hex' , 0 , max ) . replace ( / ( .{ 2 } ) / g, '$1 ' ) . trim ( ) ;
673
+ Buffer . prototype [ customInspectSymbol ] = function inspect ( recurseTimes , ctx ) {
674
+ const max = exports . INSPECT_MAX_BYTES ;
675
+ const actualMax = Math . min ( max , this . length ) ;
676
+ let str = this . hexSlice ( 0 , actualMax ) . replace ( / ( .{ 2 } ) / g, '$1 ' ) . trim ( ) ;
679
677
const remaining = this . length - max ;
680
678
if ( remaining > 0 )
681
679
str += ` ... ${ remaining } more byte${ remaining > 1 ? 's' : '' } ` ;
@@ -977,9 +975,8 @@ Buffer.prototype.toJSON = function toJSON() {
977
975
for ( var i = 0 ; i < this . length ; ++ i )
978
976
data [ i ] = this [ i ] ;
979
977
return { type : 'Buffer' , data } ;
980
- } else {
981
- return { type : 'Buffer' , data : [ ] } ;
982
978
}
979
+ return { type : 'Buffer' , data : [ ] } ;
983
980
} ;
984
981
985
982
function adjustOffset ( offset , length ) {
0 commit comments