File tree 2 files changed +13
-1
lines changed 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) {
37
37
}
38
38
39
39
p . 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
+ }
41
46
var len = Buffer . byteLength ( string ) + 1 ;
42
47
this . _ensure ( len ) ;
43
48
this . buffer . write ( string , this . offset ) ;
Original file line number Diff line number Diff line change @@ -66,6 +66,13 @@ test('cString', function() {
66
66
var result = subject . addCString ( ) . join ( ) ;
67
67
assert . equalBuffers ( result , [ 0 ] )
68
68
} )
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
+
69
76
70
77
test ( 'writes non-empty cstring' , function ( ) {
71
78
var subject = new Writer ( ) ;
You can’t perform that action at this time.
0 commit comments