wmail: keep track of buffer lengths and avoid repeated strlen calls.
This commit is contained in:
		
							parent
							
								
									be89c2a7a0
								
							
						
					
					
						commit
						c04cc87128
					
				
					 1 changed files with 15 additions and 14 deletions
				
			
		| 
						 | 
					@ -921,6 +921,7 @@ static char *ParseFromField( char *buf )
 | 
				
			||||||
    char *c;
 | 
					    char *c;
 | 
				
			||||||
    size_t maxLen = strlen( buf ) + 1;
 | 
					    size_t maxLen = strlen( buf ) + 1;
 | 
				
			||||||
    char *comment;
 | 
					    char *comment;
 | 
				
			||||||
 | 
					    size_t fullNameLen = 0, addressNameLen = 0, commentLen = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(( fullName = calloc( maxLen, sizeof *fullName )) == NULL )
 | 
					    if(( fullName = calloc( maxLen, sizeof *fullName )) == NULL )
 | 
				
			||||||
	return NULL;
 | 
						return NULL;
 | 
				
			||||||
| 
						 | 
					@ -950,14 +951,14 @@ static char *ParseFromField( char *buf )
 | 
				
			||||||
		state = STATE_QUOTED_FULLNAME;
 | 
							state = STATE_QUOTED_FULLNAME;
 | 
				
			||||||
		continue;
 | 
							continue;
 | 
				
			||||||
	    case '<':
 | 
						    case '<':
 | 
				
			||||||
		if( fullName[0] != '\0' &&
 | 
							if( fullNameLen > 0 &&
 | 
				
			||||||
		    fullName[ strlen( fullName ) - 1 ] == ' ' )
 | 
							    fullName[ fullNameLen - 1 ] == ' ' )
 | 
				
			||||||
		    fullName[ strlen( fullName ) - 1 ] = '\0';
 | 
							    fullName[ --fullNameLen ] = '\0';
 | 
				
			||||||
		state = STATE_ADDRESS;
 | 
							state = STATE_ADDRESS;
 | 
				
			||||||
		continue;
 | 
							continue;
 | 
				
			||||||
	    case '@':
 | 
						    case '@':
 | 
				
			||||||
		saveAtCharPos = strlen( fullName );
 | 
							saveAtCharPos = fullNameLen;
 | 
				
			||||||
		fullName[ saveAtCharPos ] = *c;
 | 
							fullName[ fullNameLen++ ] = *c;
 | 
				
			||||||
		continue;
 | 
							continue;
 | 
				
			||||||
	    case '(':
 | 
						    case '(':
 | 
				
			||||||
		state = STATE_COMMENT;
 | 
							state = STATE_COMMENT;
 | 
				
			||||||
| 
						 | 
					@ -971,7 +972,7 @@ static char *ParseFromField( char *buf )
 | 
				
			||||||
		} // else do the default action
 | 
							} // else do the default action
 | 
				
			||||||
	    default:
 | 
						    default:
 | 
				
			||||||
		if( fullName[0] != '\0' || !isspace ( *c ))
 | 
							if( fullName[0] != '\0' || !isspace ( *c ))
 | 
				
			||||||
		    fullName[ strlen( fullName ) ] = *c;
 | 
							    fullName[ fullNameLen++ ] = *c;
 | 
				
			||||||
	    }
 | 
						    }
 | 
				
			||||||
	    continue;
 | 
						    continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -979,13 +980,13 @@ static char *ParseFromField( char *buf )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	    switch( *c ) {
 | 
						    switch( *c ) {
 | 
				
			||||||
	    case '\\':
 | 
						    case '\\':
 | 
				
			||||||
		fullName[ strlen( fullName ) ] = *(++c);
 | 
							fullName[ fullNameLen++ ] = *(++c);
 | 
				
			||||||
		continue;
 | 
							continue;
 | 
				
			||||||
	    case '"':
 | 
						    case '"':
 | 
				
			||||||
		state = STATE_FULLNAME;
 | 
							state = STATE_FULLNAME;
 | 
				
			||||||
		continue;
 | 
							continue;
 | 
				
			||||||
	    default:
 | 
						    default:
 | 
				
			||||||
		fullName[ strlen( fullName ) ] = *c;
 | 
							fullName[ fullNameLen++ ] = *c;
 | 
				
			||||||
	    }
 | 
						    }
 | 
				
			||||||
	    continue;
 | 
						    continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1014,11 +1015,11 @@ static char *ParseFromField( char *buf )
 | 
				
			||||||
		// Since the address is finished?
 | 
							// Since the address is finished?
 | 
				
			||||||
		continue;
 | 
							continue;
 | 
				
			||||||
	    case '@':
 | 
						    case '@':
 | 
				
			||||||
		atChar = &addressName[ strlen( addressName ) ];
 | 
							atChar = addressName + addressNameLen;
 | 
				
			||||||
		*atChar = *c;
 | 
							addressName[ addressNameLen++ ] = *c;
 | 
				
			||||||
		continue;
 | 
							continue;
 | 
				
			||||||
	    default:
 | 
						    default:
 | 
				
			||||||
		addressName[ strlen( addressName ) ] = *c;
 | 
							addressName[ addressNameLen++ ] = *c;
 | 
				
			||||||
	    }
 | 
						    }
 | 
				
			||||||
	    continue;
 | 
						    continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1029,10 +1030,10 @@ static char *ParseFromField( char *buf )
 | 
				
			||||||
		state = STATE_ADDRESS;
 | 
							state = STATE_ADDRESS;
 | 
				
			||||||
		continue;
 | 
							continue;
 | 
				
			||||||
	    case '\\':
 | 
						    case '\\':
 | 
				
			||||||
		addressName[ strlen( addressName ) ] = *(++c);
 | 
							addressName[ addressNameLen++ ] = *(++c);
 | 
				
			||||||
		continue;
 | 
							continue;
 | 
				
			||||||
	    default:
 | 
						    default:
 | 
				
			||||||
		addressName[ strlen( addressName ) ] = *c;
 | 
							addressName[ addressNameLen++ ] = *c;
 | 
				
			||||||
	    }
 | 
						    }
 | 
				
			||||||
	    continue;
 | 
						    continue;
 | 
				
			||||||
	case STATE_COMMENT:
 | 
						case STATE_COMMENT:
 | 
				
			||||||
| 
						 | 
					@ -1041,7 +1042,7 @@ static char *ParseFromField( char *buf )
 | 
				
			||||||
		    state = STATE_FULLNAME;
 | 
							    state = STATE_FULLNAME;
 | 
				
			||||||
		    continue;
 | 
							    continue;
 | 
				
			||||||
	    default:
 | 
						    default:
 | 
				
			||||||
		    comment[ strlen( comment ) ] = *c;
 | 
							    comment[ commentLen++ ] = *c;
 | 
				
			||||||
		    continue;
 | 
							    continue;
 | 
				
			||||||
	    }
 | 
						    }
 | 
				
			||||||
	    continue;
 | 
						    continue;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue