-1

I received an error during compilation:

src/smtp.c:208:1: warning: control reaches end of non-void function [-Wreturn-type]

Here's the relevant code

int smtp_test_method(int socket)
{
    int smtp_code;

    if ((smtp_code = smtp_speak(socket, "VRFY root\r\n")) == 501 ||
                                                smtp_code == 250 ||
                                                smtp_code == 252)
        return 0;
    else if ((smtp_code = smtp_speak(socket, 
                            "MAIL FROM:test@test.com\r\n")) == 250) {
        if ((smtp_code = smtp_speak(socket, "RCPT TO:root\r\n")) == 250 || 
                                                          smtp_code == 550)
            return 1;
    } else 
    return smtp_code;
}

Where smtp_speak is a function that connects/EHLO's to a server and then sends a message, returning the response code as an int. Why am I getting this error?

drescherjm
  • 10,365
  • 5
  • 44
  • 64
user3408678
  • 155
  • 4
  • 17
  • 2
    Not every path in this function has a return. – tkausl Feb 13 '17 at 22:01
  • Possible duplicate of [What does "control reaches end of non-void function" mean?](http://stackoverflow.com/questions/6171500/what-does-control-reaches-end-of-non-void-function-mean) – John3136 Feb 13 '17 at 22:04

2 Answers2

3

You need a return statement after your second if:

if ((smtp_code = smtp_speak(socket, "RCPT TO:root\r\n")) == 250 || smtp_code == 550)
   return 1;
**else
   return something;**
Peter
  • 498
  • 3
  • 15
0

I added {} around each return something; and auto re-formatted.

The result is then clear.

1) Use auto formating.
2) Use {} around if/else blocks

int smtp_test_method(int socket) {
  int smtp_code;

  if ((smtp_code = smtp_speak(socket, "VRFY root\r\n")) == 501
      || smtp_code == 250 || smtp_code == 252) {
    0;
  } else if ((smtp_code = smtp_speak(socket, "MAIL FROM:test@test.com\r\n"))
      == 250) {
    if ((smtp_code = smtp_speak(socket, "RCPT TO:root\r\n")) == 250
        || smtp_code == 550) {
      return 1;
    }
  } else {
    return smtp_code;
  }
  /* Missing return */
}
chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256