Skip to contentSkip to conversation

Remove uneccessary strncmp call in imap-send count_messages

PATCH New Andy Parkins 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Remove uneccessary strncmp call in imap-send count_messages

The strncmp() call in count_messages() was doing the same comparison that strstr() did, so there was no need to call it. A little rewrite and count_messages() is simpler.

Obviously no huge benefit, as it's not frequently called. I'm just getting familiar with git.

---
 imap-send.c |   13 ++++++-------
 1 files changed, 6 insertions(+), 7 deletions(-)
imap-send.c +6 -7
index 16804ab..cfac17b 100644
@@ -1198,15 +1198,14 @@ count_messages( msg_data_t *msg )
 	int count = 0;
 	char *p = msg->data;
 
-	while (1) {
-		if (!strncmp( "From ", p, 5 )) {
-			count++;
+	while (p) {
+		p = strstr( p, "From " );
+		if ( p != NULL ) {
+			if ( p == msg->data || *(p-1) == '\n' ) {
+				count++;
+			}
 			p += 5;
 		}
-		p = strstr( p+5, "\nFrom ");
-		if (!p)
-			break;
-		p++;
 	}
 	return count;
 }
Signature · 1 line
1.4.2.3