@@ -381,12 +381,12 @@ static int is_format_patch_separator(const char *line, int len)
381
381
return !memcmp (SAMPLE + (cp - line ), cp , strlen (SAMPLE ) - (cp - line ));
382
382
}
383
383
384
- static struct strbuf * decode_q_segment (const struct strbuf * q_seg , int rfc2047 )
384
+ static int decode_q_segment (struct strbuf * out , const struct strbuf * q_seg ,
385
+ int rfc2047 )
385
386
{
386
387
const char * in = q_seg -> buf ;
387
388
int c ;
388
- struct strbuf * out = xmalloc (sizeof (struct strbuf ));
389
- strbuf_init (out , q_seg -> len );
389
+ strbuf_grow (out , q_seg -> len );
390
390
391
391
while ((c = * in ++ ) != 0 ) {
392
392
if (c == '=' ) {
@@ -405,16 +405,15 @@ static struct strbuf *decode_q_segment(const struct strbuf *q_seg, int rfc2047)
405
405
c = 0x20 ;
406
406
strbuf_addch (out , c );
407
407
}
408
- return out ;
408
+ return 0 ;
409
409
}
410
410
411
- static struct strbuf * decode_b_segment ( const struct strbuf * b_seg )
411
+ static int decode_b_segment ( struct strbuf * out , const struct strbuf * b_seg )
412
412
{
413
413
/* Decode in..ep, possibly in-place to ot */
414
414
int c , pos = 0 , acc = 0 ;
415
415
const char * in = b_seg -> buf ;
416
- struct strbuf * out = xmalloc (sizeof (struct strbuf ));
417
- strbuf_init (out , b_seg -> len );
416
+ strbuf_grow (out , b_seg -> len );
418
417
419
418
while ((c = * in ++ ) != 0 ) {
420
419
if (c == '+' )
@@ -447,7 +446,7 @@ static struct strbuf *decode_b_segment(const struct strbuf *b_seg)
447
446
break ;
448
447
}
449
448
}
450
- return out ;
449
+ return 0 ;
451
450
}
452
451
453
452
static int convert_to_utf8 (struct mailinfo * mi ,
@@ -475,7 +474,7 @@ static int convert_to_utf8(struct mailinfo *mi,
475
474
static void decode_header (struct mailinfo * mi , struct strbuf * it )
476
475
{
477
476
char * in , * ep , * cp ;
478
- struct strbuf outbuf = STRBUF_INIT , * dec ;
477
+ struct strbuf outbuf = STRBUF_INIT , dec = STRBUF_INIT ;
479
478
struct strbuf charset_q = STRBUF_INIT , piecebuf = STRBUF_INIT ;
480
479
int found_error = 1 ; /* pessimism */
481
480
@@ -530,18 +529,19 @@ static void decode_header(struct mailinfo *mi, struct strbuf *it)
530
529
default :
531
530
goto release_return ;
532
531
case 'b' :
533
- dec = decode_b_segment (& piecebuf );
532
+ if ((found_error = decode_b_segment (& dec , & piecebuf )))
533
+ goto release_return ;
534
534
break ;
535
535
case 'q' :
536
- dec = decode_q_segment (& piecebuf , 1 );
536
+ if ((found_error = decode_q_segment (& dec , & piecebuf , 1 )))
537
+ goto release_return ;
537
538
break ;
538
539
}
539
- if (convert_to_utf8 (mi , dec , charset_q .buf ))
540
+ if (convert_to_utf8 (mi , & dec , charset_q .buf ))
540
541
goto release_return ;
541
542
542
- strbuf_addbuf (& outbuf , dec );
543
- strbuf_release (dec );
544
- free (dec );
543
+ strbuf_addbuf (& outbuf , & dec );
544
+ strbuf_release (& dec );
545
545
in = ep + 2 ;
546
546
}
547
547
strbuf_addstr (& outbuf , in );
@@ -552,6 +552,7 @@ static void decode_header(struct mailinfo *mi, struct strbuf *it)
552
552
strbuf_release (& outbuf );
553
553
strbuf_release (& charset_q );
554
554
strbuf_release (& piecebuf );
555
+ strbuf_release (& dec );
555
556
556
557
if (found_error )
557
558
mi -> input_error = -1 ;
@@ -634,23 +635,22 @@ static int is_inbody_header(const struct mailinfo *mi,
634
635
635
636
static void decode_transfer_encoding (struct mailinfo * mi , struct strbuf * line )
636
637
{
637
- struct strbuf * ret ;
638
+ struct strbuf ret = STRBUF_INIT ;
638
639
639
640
switch (mi -> transfer_encoding ) {
640
641
case TE_QP :
641
- ret = decode_q_segment (line , 0 );
642
+ decode_q_segment (& ret , line , 0 );
642
643
break ;
643
644
case TE_BASE64 :
644
- ret = decode_b_segment (line );
645
+ decode_b_segment (& ret , line );
645
646
break ;
646
647
case TE_DONTCARE :
647
648
default :
648
649
return ;
649
650
}
650
651
strbuf_reset (line );
651
- strbuf_addbuf (line , ret );
652
- strbuf_release (ret );
653
- free (ret );
652
+ strbuf_addbuf (line , & ret );
653
+ strbuf_release (& ret );
654
654
}
655
655
656
656
static inline int patchbreak (const struct strbuf * line )
0 commit comments