File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -20,18 +20,26 @@ in the source distribution for its full text.
2020#define  charBytes (n ) (sizeof(CharType) * (n))
2121
2222static  void  RichString_extendLen (RichString *  this , int  len ) {
23-    if  (this -> chlen  <= RICHSTRING_MAXLEN ) {
23+    if  (this -> chptr  ==  this -> chstr ) {
24+       // String is in internal buffer 
2425      if  (len  >  RICHSTRING_MAXLEN ) {
26+          // Copy from internal buffer to allocated string 
2527         this -> chptr  =  xMalloc (charBytes (len  +  1 ));
2628         memcpy (this -> chptr , this -> chstr , charBytes (this -> chlen ));
29+       } else  {
30+          // Still fits in internal buffer, do nothing 
31+          assert (this -> chlen  <= RICHSTRING_MAXLEN );
2732      }
2833   } else  {
29-       if  (len  <= RICHSTRING_MAXLEN ) {
34+       // String is managed externally 
35+       if  (len  >  RICHSTRING_MAXLEN ) {
36+          // Just reallocate the buffer accordingly 
37+          this -> chptr  =  xRealloc (this -> chptr , charBytes (len  +  1 ));
38+       } else  {
39+          // Move string into internal buffer and free resources 
3040         memcpy (this -> chstr , this -> chptr , charBytes (len ));
3141         free (this -> chptr );
3242         this -> chptr  =  this -> chstr ;
33-       } else  {
34-          this -> chptr  =  xRealloc (this -> chptr , charBytes (len  +  1 ));
3543      }
3644   }
3745
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments