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