From ec936113070e7705899dd51a7ad178a9eff249ff Mon Sep 17 00:00:00 2001 From: Norman Rasmussen Date: Tue, 28 Dec 2021 22:55:52 -0800 Subject: [PATCH] examples/mqttc: Fix handling of getaddrinfo errors commit 36d4bfa7749ecd48ace51eddb613418350c614d7 set a hostname to work around getaddrinfo failing. getaddrinfo returns a non-zero value on error, and there should be an early return after the error message is printed. --- examples/mqttc/mqttc_pub.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/mqttc/mqttc_pub.c b/examples/mqttc/mqttc_pub.c index ea70a2d0c..6394dbf3e 100644 --- a/examples/mqttc/mqttc_pub.c +++ b/examples/mqttc/mqttc_pub.c @@ -153,9 +153,10 @@ static int initserver(const FAR struct mqttc_cfg_s *cfg) printf("Connecting to %s:%s...\n", cfg->host, cfg->port); ret = getaddrinfo(cfg->host, cfg->port, &hints, &servinfo); - if (ret < 0) + if (ret != OK) { printf("ERROR! getaddrinfo() failed: %s\n", gai_strerror(ret)); + return -1; } itr = servinfo;