Changeset 5456:651ffe277dfd

Show
Ignore:
Timestamp:
2008-07-10 06:38:25 (5 months ago)
Author:
Aron Griffis <agriffis@…>
Branch:
HEAD
Message:

Clean up error handling in mutt_copy_header

mutt_copy_header unnecessarily tests the result of each fputc/fputs (well, most
of them anyway, it's not consistent). This obfuscates the code and hides bugs.
Remove these extraneous checks since ferror/feof are checked at the bottom of
the function, and get rid of all the early returns.

Signed-off-by: Aron Griffis <agriffis@…>

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • copy.c

    r5436 r5456  
    349349   
    350350  if (mutt_copy_hdr (in, out, h->offset, h->content->offset, flags, prefix) == -1) 
    351     return (-1); 
     351    return -1; 
    352352 
    353353  if (flags & CH_TXTPLAIN) 
     
    361361    fputs(buffer, out); 
    362362    fputc('\n', out); 
    363      
    364     if (ferror (out) != 0 || feof (out) != 0) 
    365       return -1; 
    366      
    367363  } 
    368364 
     
    374370      { 
    375371        LIST *listp = h->env->in_reply_to; 
    376  
    377         if (fputs ("In-Reply-To: ", out) == EOF) 
    378           return (-1); 
    379  
     372        fputs ("In-Reply-To: ", out); 
    380373        for (; listp; listp = listp->next) 
    381           if ((fputs (listp->data, out) == EOF) || (fputc (' ', out) == EOF)) 
    382             return (-1); 
    383  
    384         if (fputc ('\n', out) == EOF) 
    385           return (-1); 
     374        { 
     375          fputs (listp->data, out); 
     376          fputc (' ', out); 
     377        } 
     378        fputc ('\n', out); 
    386379      } 
    387380 
     
    389382      { 
    390383        LIST *listp = h->env->references, *refs = NULL, *t; 
    391  
    392         if (fputs ("References: ", out) == EOF) 
    393           return (-1); 
     384        fputs ("References: ", out); 
    394385 
    395386        /* Mutt stores references in reverse order, thus we create 
     
    403394 
    404395        for (; refs; refs = refs->next) 
    405           if ((fputs (refs->data, out) == EOF) || (fputc (' ', out) == EOF)) 
    406             return (-1); 
     396        { 
     397          fputs (refs->data, out); 
     398          fputc (' ', out); 
     399        } 
    407400 
    408401        /* clearing refs from memory */ 
     
    410403          FREE (&refs); 
    411404 
    412         if (fputc ('\n', out) == EOF) 
    413           return (-1); 
     405        fputc ('\n', out); 
    414406      } 
    415407 
    416408      if (h->old || h->read) 
    417409      { 
    418         if (fputs ("Status: ", out) == EOF) 
    419           return (-1); 
    420  
     410        fputs ("Status: ", out); 
    421411        if (h->read) 
    422         { 
    423           if (fputs ("RO", out) == EOF) 
    424             return (-1); 
    425         } 
     412          fputs ("RO", out); 
    426413        else if (h->old) 
    427         { 
    428           if (fputc ('O', out) == EOF) 
    429             return (-1); 
    430         } 
    431  
    432         if (fputc ('\n', out) == EOF) 
    433           return (-1); 
     414          fputc ('O', out); 
     415        fputc ('\n', out); 
    434416      } 
    435417 
    436418      if (h->flagged || h->replied) 
    437419      { 
    438         if (fputs ("X-Status: ", out) == EOF) 
    439           return (-1); 
    440  
     420        fputs ("X-Status: ", out); 
    441421        if (h->replied) 
    442         { 
    443           if (fputc ('A', out) == EOF) 
    444             return (-1); 
    445         } 
    446  
     422          fputc ('A', out); 
    447423        if (h->flagged) 
    448         { 
    449           if (fputc ('F', out) == EOF) 
    450             return (-1); 
    451         } 
    452          
    453         if (fputc ('\n', out) == EOF) 
    454           return (-1); 
     424          fputc ('F', out); 
     425        fputc ('\n', out); 
    455426      } 
    456427    } 
     
    469440    if (flags & CH_PREFIX) 
    470441      fputs(prefix, out); 
    471     if (fputc ('\n', out) == EOF) /* add header terminator */ 
    472       return (-1); 
     442    fputc ('\n', out); /* add header terminator */ 
    473443  } 
    474444 
     
    476446    return -1; 
    477447   
    478   return (0); 
     448  return 0; 
    479449} 
    480450