File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed
Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -37,7 +37,12 @@ p.addInt16 = function(num) {
3737}
3838
3939p . addCString = function ( string ) {
40- var string = string || "" ;
40+ //just write a 0 for empty or null strings
41+ if ( ! string ) {
42+ this . _ensure ( 1 ) ;
43+ this . buffer [ this . offset ++ ] = 0 ;
44+ return this ;
45+ }
4146 var len = Buffer . byteLength ( string ) + 1 ;
4247 this . _ensure ( len ) ;
4348 this . buffer . write ( string , this . offset ) ;
Original file line number Diff line number Diff line change @@ -66,6 +66,13 @@ test('cString', function() {
6666 var result = subject . addCString ( ) . join ( ) ;
6767 assert . equalBuffers ( result , [ 0 ] )
6868 } )
69+
70+ test ( 'writes two empty cstrings' , function ( ) {
71+ var subject = new Writer ( ) ;
72+ var result = subject . addCString ( "" ) . addCString ( "" ) . join ( ) ;
73+ assert . equalBuffers ( result , [ 0 , 0 ] )
74+ } )
75+
6976
7077 test ( 'writes non-empty cstring' , function ( ) {
7178 var subject = new Writer ( ) ;
You can’t perform that action at this time.
0 commit comments