comparison src/pst2ldif.cpp @ 38:f5c024aa1dc5 stable-0-5-9

more valgrind fixes
author carl
date Sun, 12 Aug 2007 14:30:15 -0700
parents 12cac756bc05
children 183ae993b9ad
comparison
equal deleted inserted replaced
37:ddfb25318812 38:f5c024aa1dc5
554 if (str == NULL) 554 if (str == NULL)
555 ret = str; 555 ret = str;
556 else { 556 else {
557 557
558 // calculate space required to escape all the following characters 558 // calculate space required to escape all the following characters
559 x = strlen(str) +(y=(chr_count(str, ',')*2) + (chr_count(str, '\\')*2) + (chr_count(str, ';')*2) + (chr_count(str, '\n')*2)); 559 y = chr_count(str, '\\')
560 + chr_count(str, ';');
560 z = chr_count(str, '\r'); 561 z = chr_count(str, '\r');
561 if (y == 0 && z == 0) 562 if (y == 0 && z == 0)
562 // there isn't any extra space required 563 // there isn't any extra space required
563 ret = str; 564 ret = str;
564 else { 565 else {
565 buf = (char*) realloc(buf, x+1); 566 x = strlen(str) + y - z + 1; // don't forget room for the NUL
567 buf = (char*) realloc(buf, x);
566 a = str; 568 a = str;
567 b = buf; 569 b = buf;
568 while (*a != '\0') { 570 while (*a != '\0') {
569 switch(*a) { 571 switch(*a) {
570 // case ',' :
571 case '\\': 572 case '\\':
572 case ';' : 573 case ';' :
573 // case '\n':
574 *(b++)='\\'; 574 *(b++)='\\';
575 *b=*a; 575 *b=*a;
576 break; 576 break;
577 case '\r': 577 case '\r': // skip cr
578 b--;
578 break; 579 break;
579 default: 580 default:
580 *b=*a; 581 *b=*a;
581 } 582 }
582 b++; 583 b++;
583 a++; 584 a++;
584 } 585 }
585 *b = '\0'; 586 *b = '\0'; // NUL-terminate the string (buf)
586 ret = buf; 587 ret = buf;
587 } 588 }
588 } 589 }
589 return ret; 590 return ret;
590 } 591 }